Prismatic Posted July 20, 2006 Share Posted July 20, 2006 It gets set using some javascript (this works fine)[code]function setCookie(name, value){ var d = document; var today = new Date(); var expiry = new Date(today.getTime() + 30 * 24 * 60); d.cookie = name + "=" + escape(value) + "; expires=" + expiry.toGMTString() + "; path=/"; }[/code]And I want to use php to kill it right away.ive tried this[code]setcookie("MyCookie", "", time()-999999);[/code]But that doesn't kill it, so I figured I could try and make it an empty cookie:[code]setcookie("MyCookie", "");[/code]But that doesn't work either :(How can I kill this darn thing? :P Quote Link to comment https://forums.phpfreaks.com/topic/15195-why-cant-php-kill-this-cookie/ Share on other sites More sharing options...
effigy Posted July 20, 2006 Share Posted July 20, 2006 From groups.google.com:[quote]Be aware that when testing cookies this way, they will be available beforethe cookie header is send. This is because in JavaScript, 'document' is anobject and 'cookie' a property of this object.In PHP, the cookie is available not sooner then after a reload of the page. [/quote]...or you can get some milk; always works for me. Quote Link to comment https://forums.phpfreaks.com/topic/15195-why-cant-php-kill-this-cookie/#findComment-61320 Share on other sites More sharing options...
Prismatic Posted July 20, 2006 Author Share Posted July 20, 2006 Well the cookie is created when a link is clicked[code]<a onclick='savedata()' href='post.php?id=". $getpostid ."&brd=". $TopicBoardID ."&act=reply'>Go Advanced</a>[/code]So it's set on that page, and then it follows the href to the other page. So technically, doesn't it get reloaded? Shouldn't I have access to it? Quote Link to comment https://forums.phpfreaks.com/topic/15195-why-cant-php-kill-this-cookie/#findComment-61341 Share on other sites More sharing options...
effigy Posted July 20, 2006 Share Posted July 20, 2006 This example works for me:[code]<script type="text/javascript" language="javascript">function setCookie(name, value){ var d = document; var today = new Date(); var expiry = new Date(today.getTime() + 30 * 24 * 60); d.cookie = name + "=" + escape(value) + "; expires=" + expiry.toGMTString() + "; path=/"; }setCookie('test','ing');</script><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input name="submit" type="submit" /></form><?php if ($_POST) { echo 'PHP Cookies<br /><pre>', print_r($_COOKIE, true), '</pre>'; }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15195-why-cant-php-kill-this-cookie/#findComment-61345 Share on other sites More sharing options...
Prismatic Posted July 20, 2006 Author Share Posted July 20, 2006 I can view the cookies contents just fine. I just cant seem to be able to get rid of it. Quote Link to comment https://forums.phpfreaks.com/topic/15195-why-cant-php-kill-this-cookie/#findComment-61346 Share on other sites More sharing options...
ryanlwh Posted July 20, 2006 Share Posted July 20, 2006 what's the host setting of the cookie? sometimes if the host and path don't match, it won't get deleted. Quote Link to comment https://forums.phpfreaks.com/topic/15195-why-cant-php-kill-this-cookie/#findComment-61348 Share on other sites More sharing options...
effigy Posted July 20, 2006 Share Posted July 20, 2006 Manual:[quote]Cookies must be deleted with the same parameters as they were set with.[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/15195-why-cant-php-kill-this-cookie/#findComment-61349 Share on other sites More sharing options...
Prismatic Posted July 20, 2006 Author Share Posted July 20, 2006 I dunno, it gets set as you see it there on the javascript. This is how I set my login cookie when a user logs in, [code]$time = time();$expiretime = $_POST['expiry'];$expiretime = $time + $expiretime ;setcookie ("BoardCookieV3",$CookieContents, $expiretime, "/", $CookieDomain[/code]expiry is a list, it's all in seconds.How would I modify the javascript setcookie() to set it the same? Quote Link to comment https://forums.phpfreaks.com/topic/15195-why-cant-php-kill-this-cookie/#findComment-61353 Share on other sites More sharing options...
effigy Posted July 20, 2006 Share Posted July 20, 2006 This is interesting--perhaps the manual only applies to PHP itself. Anyhow, this works for me:[code]<script type="text/javascript" language="javascript">function setCookie(name, value){ var d = document; var today = new Date(); var expiry = new Date(today.getTime() + 30 * 24 * 60); d.cookie = name + "=" + escape(value) + "; expires=" + expiry.toGMTString() + "; path=/"; }</script><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input name="cookier" type="button" value="Set Cookie" onclick="javascript:setCookie('test','ing')" /> <input name="submit" type="submit" value="Refresh" /></form><?php if ($_POST) { echo 'PHP Cookies<br /><pre>', print_r($_COOKIE, true), '</pre>'; if ($_COOKIE) { echo 'Killing cookie...'; setcookie('test', 'ing', 1, '/'); } }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15195-why-cant-php-kill-this-cookie/#findComment-61361 Share on other sites More sharing options...
Prismatic Posted July 20, 2006 Author Share Posted July 20, 2006 Yep, that appears to work aswell :) Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/15195-why-cant-php-kill-this-cookie/#findComment-61377 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.