Page 1 of 1

Global variables, or something

Posted: Wed Jun 29, 2005 5:19 am
by adixtopix
Hello

Is it possible to have global variables in php, variable that will keep their value in all pages that i am using in my project?

I mean, i ask the person that is visiting my site for it's name, and keep the name in some a variable, and use tht var everywhere?

Posted: Wed Jun 29, 2005 5:31 am
by djot
-
global variable will be

Code: Select all

global $var;
$var='value';
or

Code: Select all

$GLOBALS['name']='value';
You should think of using sessions for keeping such things as username.


djot
-

Posted: Wed Jun 29, 2005 6:34 am
by phpScott
sessions is what you are looking for.

Code: Select all

session_start();
$_SESSION['name']=$_REQUEST['name'];
next page

Code: Select all

session_start();
$name = $_SESSION['name'];
echo "your name is $name";