PDA

View Full Version : Undefined variable: _SESSION


Lee Firth
06-01-2009, 05:00 AM
I have created a log out page where I have applied the "Clear Session Values" SB. The trigger is set to "before page load".

When I go to this page I get the following error message:

Notice: Undefined variable: _SESSION in C:\wamp\www\firth_web_works\logout.php on line 7

Here is the code added by this SB

<?php
if ("" == ""){
// WA_ClearSession
$clearAll = TRUE;
$clearThese = explode(",","");
if($clearAll){
foreach ($_SESSION as $key => $value){
unset($_SESSION[$key]);
}
}
else{
foreach($clearThese as $value){
unset($_SESSION[$value]);
}
}
}
?>

Ray Borduin
06-01-2009, 08:04 AM
You probably need to add:

session_start();

somewhere above that code.

Lee Firth
06-01-2009, 02:16 PM
That fixed it Ray thank you. But why should I have to add any code? The whole idea of these SB's is so that you shouldn't have to code.

Ray Borduin
06-01-2009, 02:29 PM
Yes. Usually this code is on a page with the shopping cart, which adds the session start automatically. I agree it should be added. I will log it as a bug.