unsetting a $_SESSION variable

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
Headup
Forum Newbie
Posts: 1
Joined: Mon Aug 23, 2004 4:56 pm

unsetting a $_SESSION variable

Post by Headup »

This question probably sounds really stupid, but...

When you unset a $_SESSION variable, does its value change to ""?

And if I wanted to write an IF statement based on it being unset, would i use:

Code: Select all

if($_SESSION[user] != "")
I'm sorry for the stupidity of this question, but I've been working on a set of three pages for the past day; I'm tired, I'm hungry, and I can't think straight anymore.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

the value is 0/not able to be returned

I would use empty() or isset() to check for the var being present, example:

Code: Select all

<?php
if (isset($_SESSION['user'])) {
// is present
} else {
// not present
}
?>
Post Reply