turkman Posted July 9, 2010 Share Posted July 9, 2010 in my index page the first thing i do is call set_id(); this is the code for set_id function set_id(){ add_notice("in set id"); if(isset($_COOKIE['supercookie'])){ $v =$_COOKIE['supercookie']; //update cookie setcookie("supercookie",$v,time() + 60 * 60 * 24 * 365); add_notice("cookie was set"); } else{ $charlist = "abcdefghijklmnopqrstuvwxyz0123456789"; $c = ""; for($i = 0; $i < 25; $i++ ){ $r = rand() % strlen($charlist); $c .= $charlist[$r]; } add_notice("Tried to create cookie: $c"); setcookie("supercookie",$c,time() + 60 * 60 * 24 * 365); addaction(9,"Set New id."); } } no matter how many times i refresh the page - it still doesnt register when i test for cookies if(isset($_COOKIE('supercookie'))) i set my site up, its anonymous but it keeps track of people for bans etc using cookies, but no matter what browser i try it in cookies dont work and i set my site up for safety reasons that you could only try to log in to the admin area if you had a cookie, so i cant even get into the admin area of my site. i dont know why this wont work. Quote Link to comment https://forums.phpfreaks.com/topic/207301-cant-get-cookies-to-work-getting-frustrated/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 9, 2010 Share Posted July 9, 2010 Are you developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the errors that php detects, like a header error that would prevent cookies from working, will be reported and displayed? You will save a TON of time. Quote Link to comment https://forums.phpfreaks.com/topic/207301-cant-get-cookies-to-work-getting-frustrated/#findComment-1083838 Share on other sites More sharing options...
turkman Posted July 9, 2010 Author Share Posted July 9, 2010 i dont think so, there is no real error reporting... i wrote this on my wamp server and transfered it to my webserver, works fine on wamp but on my webserver its not working at all. is there a way to change it? Quote Link to comment https://forums.phpfreaks.com/topic/207301-cant-get-cookies-to-work-getting-frustrated/#findComment-1083840 Share on other sites More sharing options...
PFMaBiSmAd Posted July 9, 2010 Share Posted July 9, 2010 Add the following two lines of code immediately after the line with your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/207301-cant-get-cookies-to-work-getting-frustrated/#findComment-1083842 Share on other sites More sharing options...
turkman Posted July 9, 2010 Author Share Posted July 9, 2010 oh thats displaying errors now the error i get is Warning: Cannot modify header information - headers already sent by (output started at /home/imgboard/public_html/mushphp/includes/top.php:9) in /home/imgboard/public_html/mushphp/includes/functions.php on line 706 which corresponds with the the code i posted above the setcookie() line... whats causing the error? Quote Link to comment https://forums.phpfreaks.com/topic/207301-cant-get-cookies-to-work-getting-frustrated/#findComment-1083845 Share on other sites More sharing options...
PFMaBiSmAd Posted July 9, 2010 Share Posted July 9, 2010 whats causing the error? The output that was started at or before line 9 in top.php - output started at /home/imgboard/public_html/mushphp/includes/top.php:9 Quote Link to comment https://forums.phpfreaks.com/topic/207301-cant-get-cookies-to-work-getting-frustrated/#findComment-1083847 Share on other sites More sharing options...
turkman Posted July 9, 2010 Author Share Posted July 9, 2010 i got it fixed... i was calling in the html include before i tried to set the cookie, thats what was causing the problem. i didnt realise cookies had to be set before any html was loaded. Quote Link to comment https://forums.phpfreaks.com/topic/207301-cant-get-cookies-to-work-getting-frustrated/#findComment-1083849 Share on other sites More sharing options...
PFMaBiSmAd Posted July 9, 2010 Share Posted July 9, 2010 Unfortunately, your development system has output_buffering turned on in the master php.ini, so code you develop won't necessarily work on your live server. I recommend turning output_buffering off so that code you develop will work on the widest range of servers. Quote Link to comment https://forums.phpfreaks.com/topic/207301-cant-get-cookies-to-work-getting-frustrated/#findComment-1083855 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.