Forum Moderators: coopster

Message Too Old, No Replies

PHP If Java 403 then Die

Extremely simple script that is not working...

         

JAB Creations

7:34 am on Jul 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An example of the useragent I'm trying to block...

Java/1.4.1_04

The code I'm using...

<?php
$useragent = $_SERVER['HTTP_USER_AGENT'];
if ($useragent=="Java/"){header("HTTP/1.0 403");die();}
?>

I'm using two = (==) to partially match the useragent. If it's Java then I want it blocked. I'm not going to try to block every specific version of Java/anything.

These bots using/posing/etc as Java come in various versions and so I simply want to block any useragents with "Java/" in the useragent.

- John

mykel79

10:12 am on Jul 2, 2006 (gmt 0)

10+ Year Member



In PHP == doesn't mean you're partially matching, it's normal matching.
One = is assigning a value.
Two = (==) is matching.

For your purpose, you can use any of a number of functions, e.g. strstr.
[pl.php.net...]

adb64

2:56 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



Hello John,

I use my .htaccess file to block these spiders:


#
# Deny bad behaving spiders
#
SetEnvIfNoCase User-Agent ^Java BadGuy
#
# Some files however can be accessed by the Bad Guys
#
SetEnvIf Request_URI "^(/error403\.php¦/robots\.txt)$" AllowBadGuy
#
# Ban the bad guys defined above, except for the files they are allowed to see
#
<Files *>
Order Deny,Allow
Deny from env=BadGuy
Allow from env=AllowBadGuy
</Files>

In my list of bad spiders I have:


SetEnvIfNoCase User-Agent ^NaverBot¦^TurnitinBot¦^ConveraCrawler¦^OmniExplorer_Bot¦^sohu¦^ichiro¦^Twiceler¦^voyager¦BecomeBot BadGuy

Change the broken pipe (¦) for a closed pipe character.

Regards,
Arjan

[edited by: jatar_k at 6:27 pm (utc) on July 2, 2006]
[edit reason] removed a couple bots to fix sidescroll [/edit]

jatar_k

6:29 pm on Jul 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you go the .htaccess route you may want to look at this monster

A Close to perfect .htaccess ban list [webmasterworld.com]

and all it's following threads

JAB Creations

9:31 pm on Jul 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Got it...

else if (eregi("Java/", "$useragent")){header("HTTP/1.0 403");die();}

Thanks guys!

- John