Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    newbie confused - help require passing a variable from parent php page to child page

    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.

    Scenario
    --------

    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.

    Thanks

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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:
    PHP Code:
    <?php
    // a.php
    $a 'Hello';
    include 
    'b.php';
    print 
    $b;
    ?>
    <?php
    // b.php
    print $a;
    $b ' World';
    ?>
    Will print "Hello World" (without quotes).
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •