/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] if cookie exists doesn’t work

I have an update feature in my site, which updates all the users files

I have a button with the text “update at next login” on the updater which when clicked sets the cookie “Update At Next Login” to “True”

and i have this php code:

[code=php]
if(@!isset($_COOKIE[“Update At Next Login”])) {
//display updater here
}else{
//display updater button here
}
[/code]

so basically when the page refreshes if the cookie doesn’t exist it will display the updater, and if the cookie does exist it displays a button instead.

But the php code doesn’t work :mad:.

I have also tried:

[code=php]
if(@$_COOKIE[“Update At Next Login”] != True) {
//display updater here
}else{
//display updater button here
}
[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 20.2010 — To help debug, do a print_r() or var_dump() of $_COOKIE and see what elements are there, and if the one you're expecting is there, make sure you have the key spelled exactly the same, including upper/lower case, in your code. (I'd also suggest leaving out the "@" operators while debugging code, in case PHP has anything "interesting" to tell you. (In fact, with isset(), "@" should not be needed anyway.)
Copy linkTweet thisAlerts:
@vinny619authorJan 20.2010 — I got it working ?

the print_r() and var_dump() didn't really help much though

but shockingly the advice you gave me about not using @ with isset() worked ?

I removed the @ and it all worked perfectly

so thankyou very very much ?

I hope you dont mind but added you to my contacts incase i need more help in the future, as you seem to know what you on about ?
Copy linkTweet thisAlerts:
@dk_zero-coolJan 20.2010 — Hmm, I'm not sure how good an idea it is to use white spaces in cookie names. If it works for you, it must be luck. Don't think all browsers will except it. White spaces is for content view only, should not be used in codes. I would use _ instead.

I'm surprised that PHP allows you to use it?
Copy linkTweet thisAlerts:
@MindzaiJan 20.2010 — Hmm, I'm not sure how good an idea it is to use white spaces in cookie names. If it works for you, it must be luck. Don't think all browsers will except it. White spaces is for content view only, should not be used in codes. I would use _ instead.

I'm surprised that PHP allows you to use it?[/QUOTE]


Yes, according to RFC2965, cookie names can have digits and/or a case insensitive "sequence of non-special, [B]non-white space[/B] characters". I would also be wary of ignoring the standard.
×

Success!

Help @vinny619 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.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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