Jump to content

passing global variable between pages php

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Ahmos

Ahmos

    Newbie

  • Members
  • PipPip
  • 12 posts
hi everybody
today i want to know how to pass global variable between many pages
assume we have page (1.php) have global and i want to print the value of this variable in page (2.php)
am using this sample code
//page one name x.php
<?

function insert($x){

global $userid ;

$userid=$x;

}


?>

//page two name 1.php

<?php

include("x.php");

insert("45454545454545");

echo "<a href=\"2.php\">go</a>";

?>

//page three name 2.php

<?

include("x.php");

echo $userid ;

?>

it not working

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
Use the $_SESSION associative array.

Documentation:
PHP: $_SESSION - Manual

You'll need to call session_start() at the beginning of every script that you'd like to have access to the session variables. Then, just assign a variable to the array in one script, and you will be able to recall it in another script.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
Ahmos

Ahmos

    Newbie

  • Members
  • PipPip
  • 12 posts
OK thanks
:)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users