clearing 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
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

clearing a session variable

Post by gurjit »

i have a session array which i declare like this

Code: Select all

<?php
session_register("stuid_list");
?>
i then later add numbers to the session variable making it an array like this:

Code: Select all

<?php
$stuid_list[] = "$sib_stuid";
?>
1. how do i clear the session variable? i have other sessions in the program, so i cannot use destroy(). i just want to clear the session values in stuid_list.
i tried

Code: Select all

<?php
session_unregister("stuid_list");
?>
but it never worked
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Do you have PHP 4.2+ installed? If so, you can use this example:

Code: Select all

<?php
session_start();

// Create session variable
$_SESSION["var1"] = "the value";

// return the variable
echo $_SESSION["var1"];
// returns: the value

// empty the variable
$_SESSION["var1"] = "";

// return the variable
echo $_SESSION["var1"];
// returns: 

?>

Hope this helps.
Image Image
Post Reply