: Temporary redirect needs to detect the URL of original page request from a search engine then redirect again to that page When you come to my client's site, it needs to verify that you are
When you come to my client's site, it needs to verify that you are 21 years of age of older. If you hit any page on the domain, it checks to see if the verified age cookie is set. If not, it takes you to a challenge page to give your date of birth, after which it forwards you to the index page (or a rejection page, if you answered incorrectly).
The problem I have run into is as follows:
If a user finds any one of the pages in a search engine, after they pass the age test, how do I send them back to page they were originally requesting?
Example:
User finds example.com/blog.php in Google, after clicking the link, they are redirected to example.com/age_verify.php. After they pass the test, how do I send them back to example.com/blog.php instead of the default example.com?
I'm flummoxed. I'm pretty sure I'm dealing with HTTP referrers, but I don't know in what capacity.
More posts by @Kaufman445
2 Comments
Sorted by latest first Latest Oldest Best
Don't rely on the referrer. You can store the URL as a query string parameter, or as a session parameter.
User hits blog.php. This page checks for the age cookie.
If age cookie not present, store current URL as a query string parameter like this - /age_verify.php?returnURL=blog.php. Alternatively, store the url in a session parameter.
Redirect the user to age_verify
After verifying age, extract the url from either the query string, or from the session, and perform another redirect.
In age_verify.php you must save $_SERVER['HTTP_REFERER'] which is the referer in a variable, say $referer.
There are multiple ways to take it from there but one simply way is that you set the cookie
and call age_verify.php?ref=$referer (easy to do through a GET form).
Before ANY output is made from age_verify.php it must check the cookie and if it is there, redirect to $referer. This is done using header("Location: $referer").
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.