John_S Posted February 3, 2009 Share Posted February 3, 2009 Hello everybody, I have a small problem with cookies, I would like to generate a value into a cookie each time a page is refreshed. Right now I use if (isset($_COOKIE['verification'])) { $v_w = $_COOKIE['verification']; setcookie('verification', "", time()-3600); } else { $salt = rand(1, 100); $v_w = crypt($salt, $salt); setcookie('verification', $v_w, time()+1); } But it gives me an empty cookie (= no cookie at all) each 1/2 page refresh. Does anybody know how could I fix this? Thanks a lot in advance! John Quote Link to comment https://forums.phpfreaks.com/topic/143659-solved-deleting-old-and-creating-a-new-cookie-each-time-a-page-is-refreshed/ Share on other sites More sharing options...
premiso Posted February 3, 2009 Share Posted February 3, 2009 setcookie('verification', $v_w, time()+1); You are setting the cookie for 1 second from now....try doing it for a bit more than that. Quote Link to comment https://forums.phpfreaks.com/topic/143659-solved-deleting-old-and-creating-a-new-cookie-each-time-a-page-is-refreshed/#findComment-753765 Share on other sites More sharing options...
John_S Posted February 3, 2009 Author Share Posted February 3, 2009 setcookie('verification', $v_w, time()+1); You are setting the cookie for 1 second from now....try doing it for a bit more than that. Yes I know but if I set it for a longer time each time that the page is refreshed the cookie will stay the same and that's what I am trying to avoid. Quote Link to comment https://forums.phpfreaks.com/topic/143659-solved-deleting-old-and-creating-a-new-cookie-each-time-a-page-is-refreshed/#findComment-753774 Share on other sites More sharing options...
premiso Posted February 3, 2009 Share Posted February 3, 2009 Let me ask you this, is there a reason you are not using sessions for this? Quote Link to comment https://forums.phpfreaks.com/topic/143659-solved-deleting-old-and-creating-a-new-cookie-each-time-a-page-is-refreshed/#findComment-753786 Share on other sites More sharing options...
John_S Posted February 6, 2009 Author Share Posted February 6, 2009 Let me ask you this, is there a reason you are not using sessions for this? Hello, Yes because I use an integrated software that doesn't support sessions :S Anyway, I have solved the issue, all I had to do is to move my code from one file to another and change it just a bit. Thanks for the help anyway! Quote Link to comment https://forums.phpfreaks.com/topic/143659-solved-deleting-old-and-creating-a-new-cookie-each-time-a-page-is-refreshed/#findComment-756097 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.