0

I am trying to get the referring URL with PHP using:

echo  $_SERVER['HTTP_REFERER']

This is working, however when I attach variables to the URL string with "&"s, the referer shows as blank. If the &'s are replaced with the html version "& a m p;", the referer works again.

I need a way for the referer to work with the "&" symbol.

The referrer is going to be captured from tracking URLs like this one:

http://www.example.com/link.php?var1=data&var2=data&var3=data

Any suggestions/solutions would be greatly appreciated!

**I realize that the referer may be spoofed, but still wish to access this information.

2
  • Where are these URLs? If they're in the source of an XHTML document, then the ampersands should be encoded. e.g. <a href="http://www.example.com?var1=data&amp;var2=data&amp;var3=data" ... is the correct form. However, none of this should be affecting the Referer... Commented Feb 19, 2011 at 21:40
  • They're typically being called from a MYSQL DB on user sites which are entered in the DB's with the "&" sign instead of the &amp Commented Feb 19, 2011 at 22:29

1 Answer 1

2

When you change the URL manually, your browser won't sent the referer with the next request. If you change the URL with firebug, then click on it, it should populate properly.

On a sidenote, you shouldn't trust the referer because people can tell their browser to submit anything they want as the referer.

Sign up to request clarification or add additional context in comments.

14 Comments

I'm aware of the security vulnerability but still would like to see where some of the urls are coming from. I wouldn't be able to change the URL with firebug since these tracking URLs are used by our users, and are placed outside of our control.
If you don't have control over the URLs how are you trying to add URL parameters?
@David I think what we're saying is that we think the ampersands may be a red herring. Are you seeing this problem with a particular browser? How are you testing, exactly? What's the exact behaviour? Can you show us an example page where one link works and sends the Referer through, and one doesn't?
The URLs are basically advertising links generated automatically for users. They place these links on their site which redirect to online advertisements. The tracking variables contain the user ID, campaign ID, and similar information which is recorded before it is redirected to the advertisement. The referring URL, IP, and other information is also recorded before the redirect.
@David No, really, the ampersands should have no effect on the Referer. @amccausl's second example works fine for me in Firefox, Chrome and Safari. Have you got any kind of odd plugins in your browser, or any proxy server in the way that might be changing things? Any security software that might be doing something odd? Tried from a different browser/computer?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.