Forum Moderators: coopster
code as it is now:
<?php
$url='AFFILIATE TARGET PAGE LINK HERE WITH MY ID ATTACHED';
header("Location:$url");
exit();
?> Ideally I'd like the redirect to fail, perhaps land on a page I specify, if the referrer is any other site or is a bot. How would I modify this? (.htaccess is not an option).
All this is the reason that many companies in order to protect and verify that user clicks are legitimate, may encode everything with a proprietary format. So instead of:
http://example.com/?affiliate_id=123
you see:
http://example.com/?id=abCdefGHJ...long signature.
That signature can include the IP, referrer, affiliate_id, time stamp etc. encoded in some way so the client end cannot manipulate this info as he doesn't know the format. At the same time both ends (tx/rx servers) can verify things and take the necessary action upon misuse.
Like with images, when someone hotlinks an image you can display a different image altogether, the images only resolve on your domain. Can a redirect page recognize the referrer and only redirect if that referrer is your own domain ?
Eg:
$method = 'GET';
$host = "example.com";
$fp = fsockopen($host, 80, $errno, $errstr, 10);
$output =
"$method $path HTTP/1.1\r\n" .
"Host: $host\r\n" .
...various HTTP headers....
"Referrer: http://www.example.com\r\n\r\n";
fwrite($fp, $output);
so the hotlinking protection will now fail as the referrer will be what you expect and you would need another filter in place like the ip.
Now with redirects say the client browses pages in example.com. Then he clicks a link that performs the redirect to another page, so the server sends these headers
header("Location: http://example.com/test.html");
exit();
And following the redirect landing on the test.html page the referrer will be blank. So no matter what conditions you have for the redirect page you won't be able to set the client's referrer (at least not in a legit way).
Now you can recognize the destination on the redirect page and do something about it. Eg:
$url = 'http://example.com/test.html';
if( isset($_GET['rurl']) ) {
$temp_url = sanitize_input($_GET['rurl']);
// parse_url validate domain/path/params if all is good..
{ $url = $temp_url; }
}
header("Location: " . $url);
exit();
or using a jscript or a post form for the link you can eliminate all popular spiders for hitting the link. But anyone who examines the html source will be able to craft a link and bypass this, the reason I mentioned the proprietary encoding earlier on.