Global variables, or something

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adixtopix
Forum Newbie
Posts: 17
Joined: Thu Jun 23, 2005 7:02 am

Global variables, or something

Post 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?
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post 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
-
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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";
Post Reply