Forum Moderators: coopster

Message Too Old, No Replies

PHP/.htaccess Referer mismatch

they are different :(

         

MarkesV6

8:30 am on Apr 21, 2006 (gmt 0)

10+ Year Member



I'm trying to log and block some referers on my site with php and htaccess. I notice that .htaccess and php referers are different. If user follows like this:

SITE1 --goes_to--> SITE2 --goes_to--> MYSITE

I get on MYSITE:
.htaccess ref => SITE1 (!)
php ref => SITE2

My .htaccess rule is like this:
RewriteCond %{HTTP_REFERER} (SITE1\.com) [NC,OR]
RewriteRule ^index.shtml$ index-bad.php?re=%1

And in index-bad.php i log refs to file $_SERVER['HTTP_REFERER']

Why they are different?..

hakre

8:39 am on Apr 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi MarkesV6,

welcome to webmasterworld. good question, it should be the same because $_SERVER is filled with values directly by your apache and this is the same apache using its server variable %{HTTP_REFERER}.

some details i would play around with: remove the ,OR from [NC,OR] in the cond line and place a [L] at the end of the rule line. maybe the [L] helps here, but this is only a quick shot.

if it's not this, check your CGI setup because the referer is passed via the CGI Interface to PHP. if it's the php-module version then check your apache server config (httpd.conf) for this, too.

MarkesV6

8:58 am on Apr 21, 2006 (gmt 0)

10+ Year Member



Oh, thank you hakre for your reply!
i'm using [OR] because there are not only one blocker ref... like this:
RewriteCond %{HTTP_REFERER} (SITE1-1\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (SITE1-2\.net) [NC,OR]
..
RewriteCond %{HTTP_REFERER} (SITE-N\.com) [NC]
RewriteRule ^index.shtml$ index-multi.php?re=%1 [L]
is this now correct?..

I was ammused to see different refs, cause i thought they should be the same.
Thanks!..

p.s. I'm going to test this on another server.