Page 1 of 1

$_SESSION not fully cleared?

Posted: Wed Nov 01, 2006 11:34 am
by lmh85
hi there, had a very big problem since i started to use $_SESSION. Its has been a very great tool for my shopping cart. But when i cleared all the items in my shopping cart, it doesn't seems to clear everything thing in the session. For example, It will appears as the same setting as its cleared if i add on the same item! *Big headache* anyone? help help!!

The below is the part where i unset or set the Session.

Code: Select all

foreach ($_POST['txtQty'] as $key => $value) {
		if((($value == 0) AND (is_numeric ($value))) OR $chkRemove[$key]=="on"){
			unset($_SESSION['cart'][$key]);
			unset($_SESSION['member'][$key]);
			unset($_SESSION['repack'][$key]);			
		}elseif(is_numeric ($value) AND ($value > 0)){
			$_SESSION['cart'][$key] = $value;
			if($chkMember[$key]=="on"){
				$_SESSION['member'][$key]="CHECKED";
			}
			if($rdRP[$key]=="1"){
				$_SESSION['repack'][$key]="1";		
			}elseif($rdRP[$key]=="2"){
				$_SESSION['repack'][$key]="2";		
			}elseif($rdRP[$key]=="3"){
				$_SESSION['repack'][$key]="3";				
			}
		}elseif(is_numeric($value)==false){
			$intNum="1";
			if($chkMember[$key]=="on"){
				$_SESSION['member'][$key]="CHECKED";
			}
			if($rdRP[$key]=="1"){
				$_SESSION['repack'][$key]="1";		
			}elseif($rdRP[$key]=="2"){
				$_SESSION['repack'][$key]="2";		
			}elseif($rdRP[$key]=="3"){
				$_SESSION['repack'][$key]="3";				
			}
		}
	}
this part is whereby i verify if the session is there or not..

Code: Select all

if(isset($_SESSION['cart'])){
	$countItems=0;
	foreach ($_SESSION['cart'] as $id => $val) {
	$countItems++;
	}
if($countItems>0){
blablabla..
}
}
The above works fine for one session item. But when i did the same to another like 'member', it just loops my new items like previous.

Posted: Wed Nov 01, 2006 11:38 am
by John Cartwright
When you want to destroy the users session, simply do

Code: Select all

$_SESSION = array();
count() may also be of interest to you, as there is no need to loop in your second snipplet.

Posted: Wed Nov 01, 2006 7:22 pm
by lmh85
hey! i had solved it! sorry, my stupidity caused so much trouble ya! i put a ">=0" which is supposed to be just ">0" .. Sorry sorry.. Thanks for the help!!