Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I've tried searching this an innumerable amount of times with different word combinations, can't seem to crack it. Apparently I do not know the right terms in this situation.

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 www.site.com/blog.php in google, after clicking the link, they are redirected to www.site.com/age_verify.php. After they pass the test, how do I send them back to www.site.com/blog.php instead of the default www.site.com?

I'm flummoxed. I'm pretty sure I'm dealing with HTTP referrers, but I don't know in what capacity.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Don't rely on the referrer. You can store the URL as a query string parameter, or as a session parameter.

  1. User hits blog.php. This page checks for the age cookie.
  2. 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.
  3. Redirect the user to age_verify
  4. After verifying age, extract the url from either the query string, or from the session, and perform another redirect.
share|improve this answer
    
Yeah buddy, nailed it! the page URI is stored in the string query, and then after the cookie is set (the age is verified), I echo out some javascript that controls what page you are directed too when click 'yes, I am of age'. Thank again. –  Brandon Mar 25 '11 at 20:20
add comment

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").

share|improve this answer
    
Thanks for trying. I attempted to implement that. Which doesn't seem to agree with me. I tried this: <? if(isset($_SERVER['HTTP_REFERER'])) { echo $_SERVER['HTTP_REFERER']; } else { echo "<script>alert('no referrer apparently');</script>"; } ?> But it only every gives me the alert saying it isn't set. –  Brandon Mar 25 '11 at 2:43
    
Do you use referer-blocking software? Some anti-spyware like zone-alarm do that. Also remember, it will only be set if you navigate to the page from another one. –  Itai Mar 25 '11 at 2:50
    
I'm not navigating per se. When you request a page like blog.php, the first thing it gives you is: <? if (!isset($_COOKIE["Age"])) { header("Location: http://site.com/age_verify.php"); } ?> So technically this first php is changing the header. Should I be saving the referrer at this point in a different cookie (or somehwere else is the same cookie I guess?). –  Brandon Mar 25 '11 at 3:04
1  
Actually, something like: header("Location: site.com/age_verify.php?ref={$_SERVER['REQUEST_URI']}"); will do and you won't even need referers. –  Itai Mar 25 '11 at 3:08
    
Thanks for the help, I was getting close with the URI method, but it only seem to give me the page I was on (not the one I came from). But, Sripathi sorted it out. –  Brandon Mar 25 '11 at 20:21
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.