Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Notifications
Mark all as read
Q&A

Load site based on cookie value in PHP

+3
−0

I need to load a site based on a cookie. I wrote code to validate that, like this.

if(!isset($_COOKIE['cookie'])){
    $domain = $_SERVER['SERVER_NAME'];
    setcookie('cookie', $cookie, time() + 31536000, '/', $domain);
    header('Location: '.$_SERVER['REQUEST_URI']);   // reload
}

But when the cookie was created the first time I got this error:

This page isn't working - redirected you too many times. Try clearing your cookies. ERR_TOO_MANY_REDIRECTS

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Checking "too early" for cookie (4 comments)

0 answers

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!

Like what we're doing? Support us! Donate