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 #181088 is a reply to message #181087] Thu, 11 April 2013 16:34 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 4/11/2013 12:27 PM, 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?
>
> On Wednesday, April 10, 2013 3:49:22 PM UTC-4, Jordan Thompson wrote:
>> Hi there. I am new to php. I want a top-level php file to call another that will generate html. When I access the top-level file, I only get:
>>
>> "hello from top"
>>
>>
>>
>> I checked the logs and there are no errors. "Hello.txt" is generated in the htdocs folder, so I know that the lower-level file is executed correctly,
>>
>>
>>
>> Here is the top-level php file ("top.php") that is located in the htdocs folder:
>>
>> <?php
>>
>> session_start();
>>
>> echo '<!DOCTYPE HTML>';
>>
>> echo '<html>';
>>
>> echo 'hello from top';
>>
>> exec("php hello.php");
>>
>> echo '</html>';
>>
>> ?>
>>
>>
>>
>> Here is the lower-level php file ("hello.php") that is also located in the htdocs folder:
>>
>> <?php
>>
>> session_start();
>>
>> echo "hello from bottom";
>>
>> phpinfo();
>>
>> touch("hello.txt");
>>
>> ?>
>>
>>
>>
>>
>>
>> This should be really easy, but I am very confused.
>>
>>
>>
>> thanks in advance!

Are you sure you don't have more than one db.php on your system?
hello.php is finding a script (or the require_once() would have failed),
but it may or may not be the right one.

I always recommend any include/require statements use paths relative to
$_SERVER['DOCUMENT_ROOT']. That way if files the including file gets
moved to another directory it still gets the correct file.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[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: Tue Nov 26 22:00:19 GMT 2024

Total time taken to generate the page: 0.04716 seconds