/    Sign up×
Community /Pin to ProfileBookmark

cookie problems

so i have these lines of code

[code=php]
……
……
setcookie(“dbworker”, $worker, time()+200);
if (isset($_COOKIE[“dbworker”]))
{
……
}
[/code]

when run the cookie is set but the if statement always returns false

why is this????

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 29.2005 — Setting the cookie puts the necessary data into the HTTP stream to send it to the client (browser) with the rest of the header data. But the server doesn't receive the cookie back until the next time the browser loads it (it then sends the cookie data back to the server).

Also note that successfully setting a cookie does not guarantee that the browser accepted it, only that it was correctly sent to the browser.
Copy linkTweet thisAlerts:
@DARTHTAMPONauthorMar 30.2005 — Well i know the browser is accepting the cookie becaue i am doing it on my own machine. To fix this would you reccommend just refreshing the page? would this fix the problem????
Copy linkTweet thisAlerts:
@NogDogMar 30.2005 — Yes, I believe it would then "see" the cookie. Of course, if this is to become a public page at some point it's probably not ideal. ?
Copy linkTweet thisAlerts:
@Stephen_PhilbinMar 30.2005 — The if should still work though. Well, according to the manual it should anyway.bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]][/QUOTE]

As you can see, it says it should return a boolean. ?
Copy linkTweet thisAlerts:
@DARTHTAMPONauthorMar 30.2005 — when you say this is not ideal for a public page are you saying iit because of lack of encryption/sescurity/etc or that the refresh is a bad idea?
Copy linkTweet thisAlerts:
@Stephen_PhilbinMar 30.2005 — The refresh is a bad idea.
Copy linkTweet thisAlerts:
@DARTHTAMPONauthorMar 30.2005 — ok then how would i get around this.
Copy linkTweet thisAlerts:
@NogDogMar 30.2005 — ok then how would i get around this.[/QUOTE]
Hard to say without knowing what it is you are trying to accomplish with that bit of code you showed us. If you just want to verify that the setcookie() worked, just do:
[code=php]
if(setcookie("dbworker", $worker, time()+200))
{
# good
}
else
{
# bad
}
[/code]
×

Success!

Help @DARTHTAMPON 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.29,
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,
)...