Jump to content


Photo

Cookie will not delete! < RESOLVED >


  • Please log in to reply
8 replies to this topic

#1 killerb

killerb
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 07 August 2006 - 12:29 PM

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!

Here's a funny thing: 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.


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

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

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

?>

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;

}
?>

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.

:-\

Experience is something you get just after you need it.

#2 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 07 August 2006 - 12:34 PM

Where is $cookieName defined?
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#3 killerb

killerb
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 07 August 2006 - 01:24 PM

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

Am I sensing right:

<?php

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

?>

?? Are these variables one in the same on the global scope?
Experience is something you get just after you need it.

#4 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 07 August 2006 - 01:42 PM

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.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#5 killerb

killerb
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 07 August 2006 - 01:46 PM

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.
Experience is something you get just after you need it.

#6 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 07 August 2006 - 02:01 PM

If $_COOKIE[$cookieName] returns blank then either there is no cookie with that name available to that script, or you have accidentally unset that element in the $_COOKIE array.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#7 killerb

killerb
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 07 August 2006 - 02:58 PM

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.

Experience is something you get just after you need it.

#8 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 07 August 2006 - 03:36 PM

Have you tried dumping the contents of the $_COOKIE array in the script where you are havig problems? E.g. print_r($_COOKIE)
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#9 killerb

killerb
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 07 August 2006 - 10:15 PM

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:
<?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

?>

Now I can go ahead and write restore_session().

Thanks for your help bud.
Experience is something you get just after you need it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users