homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

How do you change the URl referrer?

 12:14 pm on Jan 30, 2013 (gmt 0)

It's long explanation as to why ... so here is the short version of the "what" needs to be acheived:

I have traffic coming in from various sources that are constantly changing. I run them all through one page:

e.g. www.mysite.com/js/out.php

which spits the visitors out to a varied selection of pages based on certain parameters using:

Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: $locationtosend" );

once the right page for them has been found. What I need is for /js/out.php to also change the referring URl to being itself. That doesn't seem to be achievable using a PHP 301 redirect?

I need the $_SERVER['HTTP_REFERER'] to be /js/out.php for every landing page. Right now, it is the original referring site.

Any ideas?




 1:10 pm on Jan 30, 2013 (gmt 0)

You're fighting the HTTP specs. In a redirect, the original referrer is preserved as the referrer for subsequent requests.

When the browser requests the redirected-to URL, the browser resends the same referrer details as before in the request header.

edit: fix ambiuguous wording

[edited by: g1smd at 1:48 pm (utc) on Jan 30, 2013]


 1:33 pm on Jan 30, 2013 (gmt 0)

Okay - the other side then:

Is there a way to forward someone to different page using PHP but something other than a 301 redirect?

I tried almost-instant meta-refreshes but they are blocked by some browsers.


 1:52 pm on Jan 30, 2013 (gmt 0)

You can proxy the request, but your server has to do twice as much work.

All traffic has to travel into and then out of your server, both for requests and for replies and you also get into all sorts of complexity with X_FORWARDED_FOR headers.


 2:33 pm on Jan 30, 2013 (gmt 0)

How 'bout the third side: Does it absolutely have to be in the "referer" slot? Or do you simply need to preserve the information in some way? It's obviously trivial to throw a piece into the query string saying "The landing page sent me". And then use that information to do whatever it is you were going to do with the referer.


 3:02 pm on Jan 30, 2013 (gmt 0)

Also do not forget browsers can (and are) configured to
- not send referrers
- send blank referrers
- always send the top level page as referrer (e.g. this page sends me to www.example.com/yadayada, then my browser fetches that page with a referrer of www.example.com no matter where I can from)
- send some completely bogus information - some even send insults.

Privacy concerns are often at the basis for not sending the referrers you might expect.


 3:11 pm on Jan 30, 2013 (gmt 0)

yes. (again, long explanation aside) I have to change the multiple referers into one referer before it hits the landing page.

301 forwarding to the landing page with ids or parameters included in the URL is not an option.


 3:16 pm on Jan 30, 2013 (gmt 0)

You cannot change or even set the referrer: it's the browser that sends it to you. The browser chooses what to send - if anything at all.

You'll have to find another way ...

Maybe it's best to go for the long explanation of why you think you need this so badly.


 4:17 pm on Jan 30, 2013 (gmt 0)

[sigh] ... here's the dirty laundry facts ...

I generally avoid doing business with family, but my brother has been struggling so I offered to send some traffic his way. He's got 3 kids with a 4th on the way - otherwise I wouldn't be helping.

Now, I know that if he sees the referal names on the traffic I send him from my sources - he'll jump right on them and try to steal those sources. I'm giving him the traffic for cost price. I don't want to end up losing those sources myself.

So - how do I hide the referer so the only thing he sees is my 301ing middle-man domain name? His landing page also needs to see that it is my domain refering it because he has to show an extra snippet to visitors I send him.


 4:29 pm on Jan 30, 2013 (gmt 0)

One way would be to "proxy" the requests. : you deliver the content of the first html hit yourself (if needed you ask the content from the real server in your scripts). You then can make the change yourself in the content and leave the links like they are so that the second hit and all images etc. come from the real server.

Another would be to land the page and then use a combination of meta and javascript to reload another page asap. Tricky bit here: your brother will only be able to insert what he needs to insert if the browser actually tells him they came via you.

If it were me: Id' go for the proxy: nice and clean and you keep control - esp. with a party you do not trust enough - now you're sure that you keep an amount of control.


 10:30 pm on Jan 30, 2013 (gmt 0)

Someone has suggested:

<script type="text/javascript">document.location.href='http://www.mysite.com/';</script>
<script type="text/javascript">window.location.href='http://www.mysite.com/';</script>

I tried it and it seemed to work. It made the referal URl /js/out.php which is what I wanted.

The fact this was so easy to sort, has me worried! What am I missing? What's wrong with this javascript solution? Only a handful of people won't have javascript turned on. And the two scripts cover most browsers?

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved