Answer the question
In order to leave comments, you need to log in
How to redirect with cookies?
Hello, can you tell me how to do this?
It is necessary that the user enters the page and redirects him further by link1, if he has already been on this page, he will be redirected by link2, etc.
Thank you all in advance
Answer the question
In order to leave comments, you need to log in
When going to a page (for example, "index.php"), set a cookie (for example, "MyCook" with the value "test") and redirect to page1.php via:
setcookie("MyCook", "test");
header ('Location: http://sample.domain/page1.php');
RewriteCond %{REQUEST_URI} ^\/index\.php$ [NC]
RewriteCond %{HTTP_COOKIE} ^.*MyCook=test$ [NC]
RewriteRule (.*) http://sample.domain/page2.php [L]
if ($_COOKIE ["MyCook"]=="test")
header ('Location: http://sample.domain/page2.php');
else
{
setcookie("MyCook", "test");
header ('Location: http://sample.domain/page1.php');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question