Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am currently redoing some link structuring on a website. In the past we have used specific php files on the last step to direct the user to the proper place.

Example:

www.example.com/action/go-to-blue.php

or

www.example.com/action/short/go-to-red.php

www.example.com/action/tall/go-to-red.php

We are now restructuring to eliminate the /short/ or /tall/ directory. What this means is now go-to-blue.php will be doing some extra processing to make sure it sends the visitor to the proper place.

The static method of the past was quite effective, because, well, if they left from that page we knew we had it right. Now since we are 301 redirecting action/short/go-to-red.php to just action/go-to-red.php it is quite important on go-to-red.php that we realize a user may have been redirected from /short/ or /tall/.

So right now I am using HTTP_REFERRER and of course in my testing that works fine, but after a lot of reading it is clear that this is not a solid solution, so I was starting to brainstorm on other ways to check and make sure we get the proper referral information.

If we could check HTTP_REFERRER plus some other test, I would feel confident we have a pretty good system in place to send the visitor to the right place.

Some questions/comments:

  1. Could I use a session variable or a cookie to accomplish this goal?
  2. If so, would that be maintained through the 301 redirect? I don't see why it wouldn't be..
  3. Passing the url in the url is not an option in this case.
share|improve this question
1  
    
Whoops sorry. Still trying to get the hang of what is a good questions for here and what is not! –  absentx Mar 22 '12 at 20:15
    
Your question isn't bad (at least I don't think it's bad), but it's a bit on the technical side, and that would make it more suitable for Stack Overflow. However you asked a very similar question there so I wouldn't migrate (and I'm not 100% certain it should be migrated). Anyways, don't worry about a single downvote, it just means that one person doesn't find the question useful, who knows what everyone else thinks... –  Yannis Rizos Mar 22 '12 at 20:18
    
yeah once I saw it wasn't getting much here I posted on Stack, where I probably just should have first. I did get a good answer though that I suppose I could update here if necessary. –  absentx Mar 23 '12 at 3:08

2 Answers 2

up vote 1 down vote accepted

Yeah, at the end of the day HTTP is basically stateless, so you're relying on the users browser to give you accurate information to help you add state on the top of it. REFERRER and cookies are basically the two ways to achieve this (SESSION just uses a cookie for you, and almost everything else effectively folds back up into cookies or cookie-like-mechanisms.) At the end of the day though, you're at the mercy of the browsers giving you accurate REFERRER or COOKIE information.

One other thing to think about: if the redirect inside apache itself is the thing that's causing you to worry about the REFERRER tag, you could try using mod_rewrite to set the get request into an environment variable and then chain to a static script that sets a cookie and issues a LOCATION header (to do a redirect) yourself. Or if you don't trust cookies you could set a temporary portion of the GET request header and then make the target script check for that extra bit, use it, and then redirect to itself without the extra bit (so it's hidden from the users.)

share|improve this answer

If you user has cookies enabled writting into session will work but still there can be problems with users not having cookies enabled (only a small fraction of all users but still can cause problems if looking for a bullet proof solution)

share|improve this answer

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.