PHP Session variables

PHTech

Senior Member
Joined
Aug 21, 2006
Messages
588
Reaction score
0
Location
Witbank
Hi there...

How can I display a session variable into another page...? What I want to accomplish is to display for example, the name of the current logged in user...

And I want to display the variable on all the pages until the user logged out... I only need the script for the display of one variable.

ANY HELP would be so much appreciated....

THANX....!
 
Do a session.start(); at the beginning of your script. then you simply assign to your session variables by doing $_SESSION['varname'] = "varvalue";

Then you can reference these values (even possibly from a different page altogether) by reading $_SESSION['varname']

Let me know if this isn't completely clear
 
Oh, and you need to do a session.start() at the beginning of your script, even if you are only reading the session variables in that particular script. This is because the magic of sessions is accomplished with the aid of the http headers.
 
session_start(); ----> has to be before any text is output, otherwise you'll get a header error. Then like sn3rd said assign the user to the session variable $_SESSION["user"] = "user name"; then when needed you can use it to output :

<p align="right"><i><h2><?php echo($_SESSION["user"]." : logged in");?></h2></i></p>

when finished, you can have a log out button that kills your session: session_destroy(); ----> this will clear all session data. :-)
 
Top
Sign up to the MyBroadband newsletter
X