
Originally Posted by
BLiZZaRD
<?
It's generally considered better to avoid short tags. Use
instead.
$url = parse_url($HTTP_REFERER);
Expecting register_globals to be on is also inadvisable. Use the $_SERVER superglobal:
PHP Code:
$url = parse_url($_SERVER['HTTP_REFERER']);
// checks proper domain only
// no reffer needed
if ($check!='your.domain.com')
This doesn't allow for instances where no referrer information is present. Users can stop their browsers sending it, and some proxy servers strip it. A simple check would be:
PHP Code:
if($_SERVER['HTTP_REFERER']) {
/* Rest of the code nested here */
}

Originally Posted by
Twey
I disagree with [using META refresh]
So do I.
Note that if the intention is to warn the user, it would be best to send a 303 Forbidden response. Starting a PHP file with:
PHP Code:
<?php
header('HTTP/1.1 303 Forbidden');
?>
would achieve that.
The other way to handle this is through URL rewriting. The mod_rewrite guide in the Apache documentation gives an example for this very situation:
Code:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC]
RewriteRule .*\.gif$ - [F]
Just change the expected Referer [sic] string (the !^ start and .*$ end should remain) and the file extension. You could include multiple extensions with:
Code:
RewriteRule .*\.(?:gif|jpeg|jpg)$ - [F]
Mike
Bookmarks