$_SESSION variables

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
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

$_SESSION variables

Post by anthony88guy »

Does php allow you to do this? When i try retrieving the values they come up as 0.
Last edited by anthony88guy on Thu May 12, 2005 5:54 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

It is valid to do so, but I don't really see much of a reason aside from poor implementation of why you need sessions for this.

What show us where you are trying to retrieve their values, perhaps thats where you error lies.
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post by anthony88guy »

When you login, it retrieves these values, then when certain pages request them they are all ready avaliable. Is their a better way to do this?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you are performing the query, but never retrieving the values.

Code: Select all

$result = mysql_query("SELECT * FROM users WHERE user = '$user' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_assoc($result);

$_SESSION['strikeaction'] = $row['strikeaction'];
$_SESSION['armysize'] = $row['armysize'];
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post by anthony88guy »

thanks, all works now.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

those results are basically null and void once the page has finished parsing, unless you are using a persitant connection.. and even then, they could be cleared from memory.
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post by anthony88guy »

so your saying each time i need those values i should connect to the database and get them?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

basically you should only run these values under certain curcomstances only.
The main reason is that the values will be overwritten unless you consitantly have $user set to a valid user or else your session values become null.
Post Reply