Re: Calling a php file from another on apache server [message #181089 is a reply to message #181087] |
Thu, 11 April 2013 16:47 |
Tim Streater
Messages: 328 Registered: September 2010
Karma:
|
Senior Member |
|
|
In article <d2ddcea1-845c-4035-b46b-41c2a4b748e4(at)googlegroups(dot)com>,
Jordan Thompson <jorythompson(at)gmail(dot)com> wrote:
> index.php:
> <!DOCTYPE HTML>
> <html>
> Hello World<br>
>
> <?php
> session_start();
> include('../../cgi-bin2/hello.php');
> echo "hello " . $username . " from top<br>";
> ?>
>
> from html
> </html>
>
> hello.php:
> <?php
> require_once('db.php');
> echo "hello from ".$username." bottom<br>";
> $username="Alex";
> ?>
>
> db.php:
> <?php
> $username="user";
> $password="pass";
> $database="test";
> $host="localhost";
> echo "hello from ".$username." db.php<br>";
> ?>
>
>
> Here is the output from accessing index.php:
> Hello World
>
> Notice: Undefined variable: username in C:\xampp\cgi-bin2\hello.php on line 3
> hello from bottom
> hello Alex from top
> from html
Obviously $username is undefined at the point you use it in hello.php.
From which I'd deduce that your require_once('db.php') is wrong,
probably because the path to db.php is not properly specified.
--
Tim
"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
|
|
|