Jump to content

session unset not working


MDanz

Recommended Posts

Are you even sure that the IF statement is resulting to TRUE? Your code is assuming values are present and you shouldn't use a variable as the condition of a comparison to check if the value is set or has a value.

 

What does the following output?

 

$itemlisted = (isset($_POST['itemlisted'])) ? trim($_POST['itemlisted']) : '';
if (!empty($itemlisted))
{
    echo "Posted value: {$itemlisted}<br />";
   echo "SESSION Before unset: <br />";
    print_r($_SESSION);
    unset($_SESSION['items'][$itemlisted]);
   echo "SESSION After unset: <br />";
    print_r($_SESSION);
}

Link to comment
Share on other sites

it prints this

 

Posted value: 1
SESSION Before unset:
Array ( [url] => http://www.eg.com/cart.php [items] => Array ( [4] => 13 [5] => 13 [6] => 13 [7] => 14 ) ) SESSION After unset:
Array ( [url] => http://www.eg.com/cart.php [items] => Array ( [4] => 13 [5] => 13 [6] => 13

 

i think i know... why is the Array not starting from

 [0]

?

Link to comment
Share on other sites

does anyone know why the array is not starting from zero.  i get this

 

Posted value: 1
SESSION Before unset:
Array ( [4] => 13 [5] => 13 [6] => 13 [7] => 14 ) SESSION After unset:
Array ( [4] => 13 [5] => 13 [6] => 13 [7] => 14 )

 

 

when i use this code

 

$itemlisted = (isset($_POST['itemlisted'])) ? trim($_POST['itemlisted']) : '';
if (!empty($itemlisted))
{
    echo "Posted value: {$itemlisted}<br />";
   echo "SESSION Before unset: <br />";
    print_r($itemid);
    unset($_SESSION['items'][$itemlisted]);
   echo "SESSION After unset: <br />";
    print_r($itemid);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.