killerb Posted August 7, 2006 Share Posted August 7, 2006 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 hereswitch($PR['0']){case'logout':logout();};?>[/code][code]functions.php<?phpfunction 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. :-\ Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 7, 2006 Share Posted August 7, 2006 Where is $cookieName defined? Quote Link to comment Share on other sites More sharing options...
killerb Posted August 7, 2006 Author Share Posted August 7, 2006 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? Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 7, 2006 Share Posted August 7, 2006 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. Quote Link to comment Share on other sites More sharing options...
killerb Posted August 7, 2006 Author Share Posted August 7, 2006 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. Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 7, 2006 Share Posted August 7, 2006 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. Quote Link to comment Share on other sites More sharing options...
killerb Posted August 7, 2006 Author Share Posted August 7, 2006 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. Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 7, 2006 Share Posted August 7, 2006 Have you tried dumping the contents of the $_COOKIE array in the script where you are havig problems? E.g. print_r($_COOKIE) Quote Link to comment Share on other sites More sharing options...
killerb Posted August 7, 2006 Author Share Posted August 7, 2006 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]<?phpfunction 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.