Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
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() ...
#2: Post edited
Load site based on cookie value in PHP
I need to load site based on cookie, i write 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 cookie created first time i got error.![Image alt text](https://software.codidact.com/uploads/pHbcvfbMSzD4182khvz56vDh)
- 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](https://software.codidact.com/uploads/pHbcvfbMSzD4182khvz56vDh)
#1: Initial revision
Load site based on cookie value in PHP
I need to load site based on cookie, i write 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 cookie created first time i got error. ![Image alt text](https://software.codidact.com/uploads/pHbcvfbMSzD4182khvz56vDh)