Forum Moderators: coopster

Message Too Old, No Replies

Setting "Referer:"-header with php

         

squall

3:54 pm on Jul 5, 2006 (gmt 0)

10+ Year Member



I'm trying to set the Referer-header when redirecting traffic on my site. I thought something like this would work:

<?php
header("Referer: [set-adress.com");...]
header("Location: [new-location.com");...]
?>

But for some reason it doesn't. Or, the redirect works fine but the Referer is empty.

There is an old thread (non-writable) on this topic, suggesting CURL as a solution. However, my server doesn't have support for it. Surely it can't be that hard to solve anyway?

Thanks for any input.

FiRe

5:47 pm on Jul 5, 2006 (gmt 0)

10+ Year Member



Use fsockopen() instead

IanKelley

10:50 pm on Jul 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The referrer header is sent by the users browser, not the web server. Unless I'm missing something about what you're trying to do?

To put it another way, sending the browser the REFERER header will have no effect because it is not a header that is ever sent by the server, it's the other way around.

If there is a way to convince a remote web browser to send a different referrer on it's subsequent HTTP request I would be very curious to hear about it!

squall

10:22 am on Jul 7, 2006 (gmt 0)

10+ Year Member



Apparently cURL couln't be used the way I thought it could (for redirecting with new header).

Anyway, maybe another solution is possible. To "standardize" header on my site I could redirect traffic via a redirect page. However with both header-change in php and meta refresh in HTML the header doesn't seem to be updated while redirecting.

Any solution to this? From my log it looks like I succeeded once (it logged the redirect script as referer), but unfortunately I have no idea how I did it...

IanKelley

10:00 pm on Jul 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As you've noticed, when you do a Header Location redirect the previous page is always the referrer.

The only ways around this (that I know of) would be for the redirect script to do a meta (or javascript) redirect or for it to load the target url in a full page frame (the containing frame being invisible).

Using option two the redirect page would also appear in the Address bar.

squall

10:24 pm on Jul 8, 2006 (gmt 0)

10+ Year Member



I've actually tried meta refresh like this:

<meta http-equiv="Refresh" content="0;URL=http://www.new_location.com">

But that doesn't seem to set a new header I'm afraid. Or am I using the wrong code?

Any ideas if JavaScript works better for this purpose?

Thanks for all help.

IanKelley

1:49 am on Jul 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You could try this javascript:
window.location.href="http://newurl.com/";