Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$_SESSION

Status
Not open for further replies.

arm207

Programmer
Jun 13, 2006
26
US
suppose I need the variable 'loginUsername' to be global to a sesssion.

so first thing i do,
session_register("loginUsername");


I have a showUserStatus() in another script that I want to print out the value in loginUsername. How do I use the $_SESSION variable to acutally get the value of loginUsername?
 
You might find this of interest.


Second session_register is now deprectaed, meaning is going out of use, and it is strongly suggested you use the $_SESSION variable instead.

like:
Code:
session_start();
$_SESSION['loginUsername']="Some_user";

...


The to get the value out, its just a matter of doing:

$myvar=$_SESSION['loginUsername'];

This will put the value of the loginUsername session var into $myvar.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
thank you,

i see, and suppose when the user logs out, how shall I clear the $_SESSION['loginUsername'] value?
 
To unset a Variable you just issue the unset command.

Code:
session_start();
unset($_SESSION['loginUsername']);



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
or to clear the entire session
$_SESSION = array();

Don't forget you do need session_start(); on the top of every page which uses sessions, and also consider wheither or not you're concerned about non-cookie using users.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top