Jump to content

Recommended Posts

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

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

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.

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.