Jump to content

Sessions and cookies not behaving


gerkintrigg

Recommended Posts

Hi all.

 

I've got a simple logout script which used to work fine with sessions, bu as soon as I registered a cookie, everything started failing.

 

I have tried this script on its own, but I just don't get it... Both the cookie and the session still says "Yes" - and that's not what's supposed to happen.

 

Here's the code:

session_start(); 
header("Cache-control: private"); //IE 6 Fix 
$root='../';
session_destroy();
session_unregister('Logged_In');
setcookie("Logged_In", 'No', time()-60);
$go=$root.'logged_out.php';
echo 'Cookie: '.$_COOKIE['Logged_In'];
echo '<br />Session: '.$_SESSION['Logged_In'];

Link to comment
Share on other sites

Array ( [Logged_In] => No [phpSESSID] => 553531b0c3b97a97a51bf7fab11ff507 [__utma] => 198886393.755584100.1324303205.1346139057.1346144284.339 [__utmb] => 198886393.92.9.1346146550090 [__utmc] => 198886393 [__utmz] => 198886393.1345877694.329.21.utmcsr=facebook.com|utmccn=(referral)|utmcmd=referral|utmcct=/l.php )

Link to comment
Share on other sites

The $_COOKIE variables are set based on the cookies that the browser sends to the server with a http request. They won't show the result of a setcookie() statement until the next http request. Echoing a $_COOKIE variable right after a setcookie() statement doesn't show the current value in the cookie in the browser until the browser makes a http request to the server.

 

session_unregister was depreciated 10 years ago and has been completely removed in php5.4. You should use unset to remove a single $_SESSION variable and if you want to clear all $_SESSION variables, use $_SESSION = array();

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.