happyturtle Posted March 15, 2010 Share Posted March 15, 2010 I am using cookies on my website and they will not travel when you click on a link. I am using /folder/folder1/folder2/. Can anyone help me? if($_COOKIE['per'] == "" AND $_GET['per'] == "") { $limit = 24; } else { setcookie("per", $_GET['per'], time()+60*60*24*100, "/"); $limit = $_COOKIE['per']; } if($_GET['per'] != "") { header("Location: /"); } Thanks. Link to comment https://forums.phpfreaks.com/topic/195268-cookies-in-php/ Share on other sites More sharing options...
happyturtle Posted March 16, 2010 Author Share Posted March 16, 2010 This there no one that can help me with this? Link to comment https://forums.phpfreaks.com/topic/195268-cookies-in-php/#findComment-1027049 Share on other sites More sharing options...
fr34k Posted March 16, 2010 Share Posted March 16, 2010 If you can provide more code, it might help tracking it down. However, I see one potential problem with your posted code: if($_COOKIE['per'] == "" AND $_GET['per'] == "") { $limit = 24; } else { setcookie("per", $_GET['per'], time()+60*60*24*100, "/"); $limit = $_COOKIE['per']; } You're saying if "per" is empty in the cookie and the URL, then you set the limit to 24. Your else sets the "per" to the value of "per" in the URL. What if this isn't set? You could have the cookie filled and URL parameter empty, which would reset your cookie value to an empty value. You can try this if(empty($_COOKIE['per'])) { if (empty($_GET['per'])) setcookie('per', 24, time()+60*60*24*100, '/'); else setcookie('per', $_GET['per'], time()+60*60*24*100, '/'); } $limit = $_COOKIE['per']; You'll also want to verify the values of 'per.' You can find out more here: http://us2.php.net/manual/en/function.is-numeric.php Link to comment https://forums.phpfreaks.com/topic/195268-cookies-in-php/#findComment-1027099 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.