$_SESSION not fully cleared?

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
lmh85
Forum Commoner
Posts: 49
Joined: Sat Oct 28, 2006 10:49 am

$_SESSION not fully cleared?

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
lmh85
Forum Commoner
Posts: 49
Joined: Sat Oct 28, 2006 10:49 am

Post 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!!
Post Reply