Forum Moderators: coopster

Message Too Old, No Replies

Global Variable?

         

wheelibin

3:06 pm on May 9, 2004 (gmt 0)

10+ Year Member



I want to store a HTTP_GET_VARS variable and then still access it in a 2nd php block within 1 page:

e.g.

-----start of page---------
<?
$page=HTTP_GET_VARS['page'];
//this works fine and populates $page
?>

SOME HTML blah blah blah

<?
//now i'n trying to pick up the var $page but it's empty!.
?>
------end of page-------------

How can I get the value in $page to persist over the 2 blocks of php?

Birdman

4:07 pm on May 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you defining the var, $page, inside of a function()? If so, I suppose you could add this line before defining $page:

global $page;

Check the Variable scope [php.net] section of the manual for more info.

wheelibin

4:33 pm on May 9, 2004 (gmt 0)

10+ Year Member



thanks for the quick reply

The var 'page' is being passed from another page via "? page="
The problem is that I only seem to be able to read the $HTTP_GET_VARS['page'] in the first php block and it's not available to the second one.

Birdman

8:17 pm on May 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I doubt it is the true problem, but you are using a depracated array name. The current recommended way to acces query string vars is $_GET['page'].

How about simply using $_GET['page'] to acces the var, rather than trying to put it in a local variable($page).