[nycphp-talk] PHP/setcookie: Can someone work with me on cookies offsite here?
Phillip Powell
phillip.powell at adnet-sys.com
Fri Aug 27 14:26:37 EDT 2004
Daniel Kushner wrote:
>This is how IE handles cookies - I'm not too sure about other browsers.
>
>The session cookies aren't stored on the clients file system but in
>memory only. Non-session cookies are stored on the file system. When
>you set your cookie with a '0', the data is in memory, and when you're
>doing "time() - 86400", it's on the file system. Try
>setcookie($projectFolderName, '', 0, '/');
>
>-Daniel
>
>
>
Thanx. Apparently redirection has now failed and so cookies nor
sessions delete of course. I can't figure out what is going on other
than that something is being tossed into the HTTP headers to cause
header() to bomb out (no warnings, no errors, no nothing), thus, no
redirection, so I just plain gave up and threw down some rather
way-substandard PHP code to band-aid it:
[PHP]
/**
* Logout
*
* @access public
* @return mixed HTML (returns HTML only if header() fails)
*/
function &logout() { // STATIC
VOID OR HTML STRING METHOD
global $projectFolderName, $projectURLPath, $willAuthenticate,
$projectAcronym, $phpVersionInt;
if ($willAuthenticate) setcookie("$projectFolderName", '',
time() - 86400, '/'); // DELETE COOKIE
foreach ($_SESSION as $key => $val) {
if (preg_match("/^{$projectAcronym}_/i", $key)) {
$_SESSION[$key] = '';
unset($_SESSION[$key]); // DELETE ALL
PROJECT SESSION VARIABLES
}
}
global $_SESSION;
@flush();
if ((int)$phpVersionInt > 420) @ob_flush(); // YOU CAN ONLY
FLUSH OUTPUT BUFFER IN PHP VERSIONS 4.2+
clearstatcache();
header('Location: http://' . $_SERVER['SERVER_NAME'] .
"$projectURLPath/index.php"); // DEFAULT REDIRECT TO MAIN PAGE
$html .= "\n<script
type=\"text/javascript\">\n<!--\nlocation.href = 'http://" .
$_SERVER['SERVER_NAME'] . "$projectURLPath/index.php';\n//-->\n" .
"</script>\n<noscript>\n <meta http-equiv=\"Refresh\"
contents=\"0;URL=http://" . $_SERVER['SERVER_NAME'] .
"$projectURLPath/index.php\">\n</noscript>\n";
return $html;
}
[/PHP]
This works, however.
Phil
>On Fri, 27 Aug 2004 13:08:56 -0400, Phillip Powell
><phillip.powell at adnet-sys.com> wrote:
>
>
>>Daniel Kushner wrote:
>>
>>
>>
>>>Hi Phil,
>>>
>>>It's not easy deleting session cookies (if that's what you're using,
>>>and don't confuse with PHP sessions). I would suggest changing their
>>>value to something like -1, 0, or false.
>>>
>>>
>>>
>>>
>>Change the cookie value? I can try that, I am using a session cookie
>>(as well as PHP sessions)
>>
>>setcookie("$projectFolderName", "$username", 0, '/');
>>
>>And upon deletion I do this:
>>
>>setcookie("$projectFolderName", '', time() - 86400);
>>
>>No dice though. :(
>>
>>Phil
>>
>>
>>
>>
>>
>>>-Daniel
>>>
>>>
>>>On Fri, 27 Aug 2004 12:35:18 -0400, Phillip Powell
>>><phillip.powell at adnet-sys.com> wrote:
>>>
>>>
>>>
>>>
>>>>I'd rather not bug the list with this but I've stumped even the superior
>>>>Chris Bielanski with this one..
>>>>
>>>>I am writing a logout.php script that simply deletes the cookie, deletes
>>>>the session variables and redirects.
>>>>
>>>>Right now, it only redirects. The cookie and session variables remain
>>>>intact in spite of my best efforts. I'm at a loss as to what to do at
>>>>this point so I'm appealing to higher minds on this one. Someone
>>>>contact me and I'll send the code for review and tell me what I did
>>>>wrong, please.
>>>>
>>>>Thanx
>>>>Phil
>>>>
>>>>--
>>>>---------------------------------------------------------------------------------
>>>>Phil Powell
>>>>Multimedia Programmer
>>>>BPX Technologies, Inc.
>>>>#: (703) 709-7218 x107
>>>>Fax: (703) 709-7219
>>>>
>>>>_______________________________________________
>>>>New York PHP Talk
>>>>Supporting AMP Technology (Apache/MySQL/PHP)
>>>>http://lists.nyphp.org/mailman/listinfo/talk
>>>>http://www.newyorkphp.org
>>>>
>>>>
>>>>
>>>>
>>>>
>>>_______________________________________________
>>>New York PHP Talk
>>>Supporting AMP Technology (Apache/MySQL/PHP)
>>>http://lists.nyphp.org/mailman/listinfo/talk
>>>http://www.newyorkphp.org
>>>
>>>
>>>
>>>
>>>
>>--
>>---------------------------------------------------------------------------------
>>Phil Powell
>>Multimedia Programmer
>>BPX Technologies, Inc.
>>#: (703) 709-7218 x107
>>Fax: (703) 709-7219
>>
>>_______________________________________________
>>New York PHP Talk
>>Supporting AMP Technology (Apache/MySQL/PHP)
>>http://lists.nyphp.org/mailman/listinfo/talk
>>http://www.newyorkphp.org
>>
>>
>>
>_______________________________________________
>New York PHP Talk
>Supporting AMP Technology (Apache/MySQL/PHP)
>http://lists.nyphp.org/mailman/listinfo/talk
>http://www.newyorkphp.org
>
>
>
--
---------------------------------------------------------------------------------
Phil Powell
Multimedia Programmer
BPX Technologies, Inc.
#: (703) 709-7218 x107
Fax: (703) 709-7219
More information about the talk
mailing list