FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Calling a php file from another on apache server
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Calling a php file from another on apache server [message #181095 is a reply to message #181087] Thu, 11 April 2013 23:42 Go to previous messageGo to previous message
David Robley is currently offline  David Robley
Messages: 23
Registered: March 2013
Karma:
Junior Member
Jordan Thompson wrote:

> Thanks for helping with these apparently fundamental concepts (I do C++,
> C, Java, etc, this web-stuff is new to me.) I am able to get the first
> tier of include to work, but the second does not seem to make its
> variables available to the parent.:
>
> 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
>
>
> NOW what am I doing wrong?

Include/require effectively put the contents of the requested file(s) in the
program flow; so here is roughly what is happening based on the code you
show above:

index.php:
<!DOCTYPE HTML>
<html>
Hello World<br>
>
<?php
session_start();
//include('../../cgi-bin2/hello.php');

//require_once('db.php');
$username="user";
$password="pass";
$database="test";
$host="localhost";
echo "hello from ".$username." db.php<br>";

echo "hello from ".$username." bottom<br>";
$username="Alex";

echo "hello " . $username . " from top<br>";
?>
from html
</html>


--
Cheers
David Robley

Plagiarism is the sincerest form of flattery.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Error while Generating SiteMap
Next Topic: Calling child class from parent class
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 06:36:57 GMT 2024

Total time taken to generate the page: 0.03755 seconds