Devilix Devilix - 1 year ago 65
PHP Question

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:"); }

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

Answer Source

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

|| => OR


&& => AND


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

should be

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

Reading Material

Logical Operators

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download