Devilix
Devilix

Reputation: 323

PHP - redirect if there isn't a cookie or another cookie

I have cookie A and cookie B, and want to redirect to Google if no cookies are present, but if one of the two is present must not redirect.

I have made/try this one:

if (!isset($_COOKIE['Access']) || !isset($_COOKIE['Guest'])) {
header ("location: https://www.google.com"); }

but without success... How can i solve it? Thanks

Upvotes: 0

Views: 195

Answers (1)

Script47
Script47

Reputation: 14540

If you want it to redirect when NONE of your cookies are present, then you need the AND (&&) operator not the OR (||).

|| => OR

and

&& => AND

therefore

if (!isset($_COOKIE['Access']) || !isset($_COOKIE['Guest'])) {

should be

if (!isset($_COOKIE['Access']) && !isset($_COOKIE['Guest'])) {

Reading Material

Logical Operators

Upvotes: 4

Related Questions