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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP and variables help!!

    Hi

    If I have a PHP page called page1.php thats sets a variable, ie

    $myvariable=1;

    and i have a PHP page call page2.php that has an include(page1.php);

    will it be able to know the value of the variable that is created in the other page?

    If not is there a way i can get it to do this?

    thanks
    steve

  • #2
    Regular Coder
    Join Date
    Mar 2005
    Location
    Pakistan
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    u can have the value of page1.php in page2.php, if u have properly included the file.
    otherwise u can do it by declaring any variable as Global
    God helps those who help others.

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    kool how do you declare as a global?

  • #4
    New Coder
    Join Date
    Aug 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Yup

    Code:
    <? global $myvariable1; ?>

  • #5
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    the_include.php
    PHP Code:
    <?php
    echo "this is the include";
    $variable='include';
    ?>
    the_page.php
    PHP Code:
    <?php
    echo "The main page";
    $variable="main_page";
    include 
    'the_include.php';
    echo 
    '$variable='.$variable;
    ?>
    will give:
    Code:
    main_page
    this is the include
    $variable=include


  •  

    Posting Permissions

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