/    Sign up×
Community /Pin to ProfileBookmark

working cookies ?

Hi,

I would like to set up a cookie containing some preferences from my users so that the next time, these are applied automatically. i do not know how to do that in my html/php script. could you point me towards a working howto ? I found lots on the net that did not work (even if I have xp set to accept those … )…

thanks a lot !

to post a comment
HTML

2 Comments(s)

Copy linkTweet thisAlerts:
@TaschenOct 24.2006 — Nice and easy with php:
[code=php]
//The cookie user pref with user preference values of... is set for one day for //the domain mydomain.com.
setcookie('user_pref', 'user preference values', mktime()+86400, '/');
[/code]


[URL=http://www.php.net/cookies]www.php.net/cookies[/URL] will tell you more.

It may be that the reason the other scripts you have tried have failed is because you have output content before you have set the cookie. A cookie must be set before any content (or headers) are sent to the browser.

Try this simple exercise
[code=php]
#echo 'replace/remove hash to set/not-set cookie';
setcookie('myname', 'bob', mktime()+86400, '/');

echo $_COOKIE['myname'];
//Will return "bob" if the cookie was succesfully set
[/code]


The above should all be done in a php file (you knew that though!)
Copy linkTweet thisAlerts:
@patimagesauthorOct 24.2006 — thanks ! quick and efficent !!! love it !!!
×

Success!

Help @patimages 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...