View Full Version : newbie confused - help require passing a variable from parent php page to child page

11-01-2006, 12:33 PM
Help !

Newbie needs assistance here. I've searched the forums and read the FAQs in relation to this subject but haven't found a solution to my problem.


Page A (a.php) defines three variables in relation to Shoutcast servers -

namely - IP address, port number and admin password

Page B (b.php) has been coded to parse that Shoutcast server's logfile and plot all listener stats included country of IP origin etc etc

Now - here's the problem.....

Page B is called via a require function in Page A.

However Page B needs to grab the above mentioned variables from Page A in order to work.

I'm looking for a way in which I can get page B to grab the three variables already defined in Page A.

Don't really want to go down the cookie road - but would prefer if there is any way in which I can get those details across to Page B.

Security is not that much of an issue as the function I'm trying to code will be available only to individual account holders after they have logged in.

Any help would be really appreciated.


11-01-2006, 01:39 PM
When you include/require a page on your filesystem the code in the included file gets executed in the scope in which it was included/required from. That means that:

// a.php
$a = 'Hello';
include 'b.php';
print $b;
// b.php
print $a;
$b = ' World';

Will print "Hello World" (without quotes).

11-01-2006, 01:56 PM
Good solution there from marek_mar, but you can also use Session variables and as such, these variables will be available whilst the session is active across the whole site.

Good luck