Jump to content

Cookie will not delete! < RESOLVED >


killerb

Recommended Posts

I use sessions, yes.

On login, if the user has opted for persistent logins, I write a cookie with serialized $_SESSION data. That works great, I can close my browser and be still logged in by unserializing and restoring the data to a new session. (Dont tell me I need to up my security! - I just want to get it running first, and its a snag)

Problem is, I can't delete that blimmin' cookie! Even after running logout(), I can still access the private sections!

[b]Here's a funny thing:[/b] I echo $_COOKIE[$cookieName] from within the function, I get a notice: 'Undefined index 'myUnique''. - Huh? Cookies are globals, right? Yet, echoing the same from index.php displays the serialized data.

Maybe I'm doing something wrong, but I can't see it. I thought I would have worked it out by now.


[code]
index.php
<?php
// $PR=explode('/',$_SERVER['REQUEST_URI']); (Page Request)

//echo $_COOKIE[$cookieName];// works fine here

switch($PR['0']){
case'logout':logout();
};

?>
[/code]

[code]
functions.php
<?php

function logout(){
  global $S;global $cookieName;global $keyWords;
  require_once(lang('keyWords'));

  //echo $_COOKIE[$cookieName];// Undefined index 'myUnique'
  //echo $cookieName;// myUnique

  $lp=$_SESSION['last_page'];

  setcookie($cookieName,'',time() - 1,'/');  
  $_SESSION=array();
  setcookie(session_name(), '',time() - 1 ,'/');
  session_destroy();
// All session and cookie data should be deleted now

  $S=&new antzSession;// includes session_start(), and initializes $_SESSION to visitor status
  add_success($keyWords['4']);
  add_last_page($lp);
  go_last_page();
  echo href($lp,$keyWords['4']);
  exit;

}
?>
[/code]

I dunno. It deletes the session ok (FF tells me), but there is no action on the setcookie($cookieName) line.

Is there something I am doing wrong? As much as I can make out, I have done it all by the book.

:-\
Link to comment
Share on other sites

It is defined in globals.php, before antzSession is included and instantiated.

Am I sensing right:

[code]
<?php

$_COOKIE[$cookieName] == $cookieName == $_SESSION[$cookieName]

?>
[/code]

?? Are these variables one in the same on the global scope?
Link to comment
Share on other sites

Well no. By accessing $_COOKIE[$cookieName], if $cookieName == "MyUnique" you are getting the value of a cookie found with the name "MyUnique" if there was one. The value isn't the same as the name. There will not be a corresponding key of that name in the $_SESSION array unless you set one there.
Link to comment
Share on other sites

I know, $_COOKIE is an array. I dont know why I even got that idea!

Its a real bizzare problem, it is as though $_COOKIE is not available inside the function!

$cookieName is there alright, and it prints out OK, but $_COOKIE[$cookieName] is set but blank!

$_COOKIE[$cookieName] prints properly from everywhere else I tried.
Link to comment
Share on other sites

Cookies are globals, right? So they are available to all scripts equally, aren't they?

thing is, when I go to the private section again, it shows all the serialised data.

It really has me baffled. I just tried doing all the same stuff again, hoping it might decide to work.
Link to comment
Share on other sites

Well you know what . . .

It decided to work this morning!

That is good by me, that is what I want it to do. But the thing I don't like about it is that I don't know why!

The function looks exactly the same as the one I started with and posted up top here. I thought it might have been a rogue cookie that I had set earlier, but even so, I actually deleted all the myUnique cookies when I was trying to debug it last night.

This has me confused, it really does. Normally there is some explanation to these sorts of things.

I'm actually beginning to wonder if the computer was just playing with me.

??? ??? ???

Here is the working code for the record:
[code]
<?php

function logout(){
  global $S;global $cookieName,$_COOKIE;global $keyWords;
  require_once(lang('keyWords'));
   
setcookie($cookieName,'',time() - 4800,'/'); 
  //print_r($_COOKIE);
$_SESSION=array(); 
    setcookie(session_name(), '',time() - 1 );
    session_destroy();
   

        $S=&new antzSession;
    //add_success($keyWords['5'].BR);
    //echo 'success';
    go_last_page();exit;
 
 
}// end function

?>
[/code]

Now I can go ahead and write restore_session().

Thanks for your help bud.
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.