/    Sign up×
Community /Pin to ProfileBookmark

Append to a cookie

Hello, this may be a retarded question but I have a site with image galleries. I want to have a ‘add to favorites’ link that will set a cookie on the user’s computer.

So if I hit tom’s gallery, and hit add to fav, it would put the galleryID into the cookie. If I then go to steve’s gallery and do the same, it add it to the cookie, instead of over riding it. Then I can show them a list of all the galleries in there favorites by looping through the info in the cookie. Is this possible? Up till now I have only used single item data for cookies. Normally I would just use a database table for this but since the visitor does not login to view galleries, I just wasnted them to be able to do this.

I am using the set_cookie() in php.

[CODE]setcookie(‘galleryfavs’,$_GET[“fav”],time()+60*60*24*30,’/’,’mysite.net’);[/CODE]

thanks for any help or clarity on this matter.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Feb 15.2007 — You could store the favorites in an array and store the array in the cookie.[code=php]<?php
setcookie("fav[0]", "gallery1");
setcookie("fav[1]", "gallery3");
setcookie("fav[2]", "gallery5");
setcookie("fav[3]", "gallery7");
?>[/code]
Retrieve the information this way:[code=php]<?php
// after the page reloads, print them out
IF (isset($_COOKIE['fav'])) :
IF (is_array($_COOKIE['fav'])) :
FOREACH ($_COOKIE['fav'] as $key => $thisGALLERY) {
echo $key . ": " . $thisGALLERY . "<br>";
ENDFOREACH;
ELSE
echo "1: " . $_COOKIE['fav'] . "<br>";
ENDIF;
ENDIF;
?>[/code]
Copy linkTweet thisAlerts:
@tripwaterauthorFeb 15.2007 — Thank you NightShift58. I will give that a go.
×

Success!

Help @tripwater spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...