Monkuar Posted March 7, 2012 Share Posted March 7, 2012 if a user clicks ?hide=1 or ?hide=2 it does if (isset($_GET['hide'])){ $id = intval($_GET['hide']); setcookie('hide', ''.$id.'',time()+32000000); header('Location: index.php'); exit; } How do I make it so if they click ?hide=1 it ad's 1, but what if they do ?hide=2 also? it would need to be 1,2 not just 2. Link to comment https://forums.phpfreaks.com/topic/258480-need-to-add-to-cookie/ Share on other sites More sharing options...
requinix Posted March 7, 2012 Share Posted March 7, 2012 By putting in logic that does one thing if it's 1 and another thing if it's 2? Link to comment https://forums.phpfreaks.com/topic/258480-need-to-add-to-cookie/#findComment-1324949 Share on other sites More sharing options...
Monkuar Posted March 7, 2012 Author Share Posted March 7, 2012 By putting in logic that does one thing if it's 1 and another thing if it's 2? Brain is absolutely trash today. I just need to set my cookie to 1,2 if the data is 1 and somone got ?hide=2, it needs to be 1,2. How to do this? Now if they do ?hide=2 it needs to be just 1, lol sorry but this is killing me Link to comment https://forums.phpfreaks.com/topic/258480-need-to-add-to-cookie/#findComment-1324956 Share on other sites More sharing options...
requinix Posted March 7, 2012 Share Posted March 7, 2012 if the cookie is empty and hide is 1 or 2 { set the cookie to 1 } else if hide is 2 { set the cookie to 1,2 } else { anything that needs to happen here? } Link to comment https://forums.phpfreaks.com/topic/258480-need-to-add-to-cookie/#findComment-1324972 Share on other sites More sharing options...
Dathremar Posted March 7, 2012 Share Posted March 7, 2012 I am guessing that monkuar needs this to toggle some element on client side. So the logic should be if ?hide=1 and 1 is in the cookie remove it otherwise add it. Same thing for ?hide=2. So in order to do this, You need to get the cookie content ($_COOKIE['cookie_name']) check if the value is in there and set the new value. Link to comment https://forums.phpfreaks.com/topic/258480-need-to-add-to-cookie/#findComment-1324975 Share on other sites More sharing options...
requinix Posted March 7, 2012 Share Posted March 7, 2012 If it's a client-side thing then this could be done in JavaScript... Link to comment https://forums.phpfreaks.com/topic/258480-need-to-add-to-cookie/#findComment-1324978 Share on other sites More sharing options...
Monkuar Posted March 7, 2012 Author Share Posted March 7, 2012 If it's a client-side thing then this could be done in JavaScript... $cat_ids = (isset($_COOKIE['collapseprefs'])) ? explode(',', $_COOKIE['collapseprefs']) : array(); I have this code that reads arrays like 1,2,3,4 i need to get arrays like that stored in a cookie... but like what if somone clicked ?hide=4 then the array needs to become 1,2,3 how? Link to comment https://forums.phpfreaks.com/topic/258480-need-to-add-to-cookie/#findComment-1324984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.