stevemacdonald99 Posted September 30, 2009 Share Posted September 30, 2009 PHP newbie. Apologies if this has been answered elsewhere. I have Firefox 3.5.3. I use the following code, from the file test2.php to create, and attempt to increment the cookie, 'centon'. It will create the cookie, but never increment it-it is always zero. Any ideas? THANKS!!!!!! <?php //check if the $count variable has been associated with the count cookie if (!isset($centon)) { $centon = 2; } else { $centon++; } if (!setcookie("centon", $centon, time()+600, "/", "", 0)) { echo("<p>bad assignment</p>"); } ?> <html> <head> <title>Session Handling Using Cookies</title> </head> <body> This page has been displayed: <?=$centon ?> times. </body> </html> Link to comment https://forums.phpfreaks.com/topic/176093-trying-to-increment-a-cookie-value/ Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 You need to load the value from the cookie first, then increment it, then save it back to the cookie. You could add this at the top of your page.;; $centon = $_COOKIE['centon']; Link to comment https://forums.phpfreaks.com/topic/176093-trying-to-increment-a-cookie-value/#findComment-927886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.