cmgmyr Posted March 23, 2007 Share Posted March 23, 2007 Ok...this I don't get... I have: if (isset($remember)){ setcookie("user","$info",time()+1209600); }else{ setcookie("user","$info",0); } I can echo $info and it looks fine, but when i echo the cookie...nothing. I have this in 2 sites on my local computer...one works...one doesn't. I don't know why it's not setting the cookie. (it's going to the else statement) any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/ Share on other sites More sharing options...
trq Posted March 23, 2007 Share Posted March 23, 2007 Where is $remember being set? Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213192 Share on other sites More sharing options...
kenrbnsn Posted March 23, 2007 Share Posted March 23, 2007 Where is the variable "$remember" coming from? Ken Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213193 Share on other sites More sharing options...
cmgmyr Posted March 23, 2007 Author Share Posted March 23, 2007 it's just a checkbox on the login form...but with or without it, it should still set the cookie. The information sent from the form has been validated and set into variables ($info) and I can echo $info. But the actual cookie is not setting. Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213194 Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 If you are setting on localhost read this: http://www.aeonity.com/frost/php-setcookie-localhost-apache Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213197 Share on other sites More sharing options...
cmgmyr Posted March 23, 2007 Author Share Posted March 23, 2007 thanks frost but that didn't work either. It also doesn't make sense why 1 site works and 1 doesn't... ??? Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213199 Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 It would if they are both set on localhost. Is there a way to distinguish the two? Maybe append the cookie name for the site. IE site one use the name site1_user and for site2 use site2_user see if that works. Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213201 Share on other sites More sharing options...
cmgmyr Posted March 23, 2007 Author Share Posted March 23, 2007 Yes, I did change the cookie names, delete all my cookies, tried again...nothing Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213202 Share on other sites More sharing options...
cmgmyr Posted March 23, 2007 Author Share Posted March 23, 2007 *Bump* any ideas? Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213412 Share on other sites More sharing options...
mjlogan Posted March 23, 2007 Share Posted March 23, 2007 What are you running IIS, Apache, PHP5? Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213415 Share on other sites More sharing options...
cmgmyr Posted March 23, 2007 Author Share Posted March 23, 2007 apache, php4, xp pro Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213418 Share on other sites More sharing options...
jitesh Posted March 23, 2007 Share Posted March 23, 2007 Debug like this if (isset($remember)){ echo "Set cookie"; setcookie("user","$info",time()+1209600); }else{ echo "delete cookie"; setcookie("user","$info",0); } echo " < pre > "; print_r($_COOKIE); Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213422 Share on other sites More sharing options...
cmgmyr Posted March 23, 2007 Author Share Posted March 23, 2007 I'm on a different computer now but now I'm getting this... Line 59 is: setcookie("user","$info",0); delete cookie Warning: Cannot modify header information - headers already sent by (output started at C:\web\www\htdocs\tarson\header.php: in C:\web\www\htdocs\tarson\includes\do_login.php on line 59 Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213456 Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 You want to look at this line and see what it is sending out information to the browser: output started at C:\web\www\htdocs\tarson\header.php:Cool i (note cool i is because no smilieys were turned off) Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213462 Share on other sites More sharing options...
cmgmyr Posted March 23, 2007 Author Share Posted March 23, 2007 header.php is just my header html i'm not using header: anywhere in the script Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213474 Share on other sites More sharing options...
mjlogan Posted March 23, 2007 Share Posted March 23, 2007 Remember that you can't set cookies after HTML has been displayed. Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213480 Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 Setcookies act the same as a header, they cannot be sent after output was sent to the browser. Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213486 Share on other sites More sharing options...
cmgmyr Posted March 23, 2007 Author Share Posted March 23, 2007 hmmmm...then why would it work for 2 other sites on my localhost (I checked another one too)? ??? Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213489 Share on other sites More sharing options...
cmgmyr Posted March 23, 2007 Author Share Posted March 23, 2007 ok ok sorry I found it... When I made my new config file I for got to copy: <?php $phpver = phpversion(); if ($phpver < '4.1.0') { $_GET = $HTTP_GET_VARS; $_POST = $HTTP_POST_VARS; $_SERVER = $HTTP_SERVER_VARS; } if ($phpver >= '4.0.4pl1' && strstr($_SERVER["HTTP_USER_AGENT"],'compatible')) { if (extension_loaded('zlib')) { ob_end_clean(); ob_start('ob_gzhandler'); } } else if ($phpver > '4.0') { if (strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip')) { if (extension_loaded('zlib')) { $do_gzip_compress = TRUE; ob_start(array('ob_gzhandler',5)); ob_implicit_flush(0); } } } $phpver = explode(".", $phpver); $phpver = "$phpver[0]$phpver[1]"; if ($phpver >= 41) { $PHP_SELF = $_SERVER['PHP_SELF']; } if (!ini_get("register_globals")) { import_request_variables('GPC'); } ?> now it works like a charm! Thanks for all the help guys! The moral of the story...copy your WHOLE config file... Link to comment https://forums.phpfreaks.com/topic/43914-solved-setcookieon-fire/#findComment-213494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.