View Full Version : Nothing up my sleeves...

02-28-2007, 01:46 AM
I have this code:

if (strstr($_SERVER["HTTP_USER_AGENT"], "VoilaBot")) {header("location: http://www.parnasse.com/trap.html");}

I'd like to be able to do this:

if (strstr($_SERVER["HTTP_USER_AGENT"], "")) {header("location: http://www.parnasse.com/trap.html");}

If there's nothing captured in the HTTP_USER_AGENT (ie: "")then it would location:http:/ /www.parnasse.com/trap.html

But as it is, I get Warning: strstr() [function.strstr]: Empty delimiter.

Tips, please? :D

02-28-2007, 02:13 AM
How about this: add function to a globally required site config file:

function agentCheck() {
$agent = (!empty($_SERVER["HTTP_USER_AGENT"])) ? $_SERVER["HTTP_USER_AGENT"] : 'Not Defined';
$agentOK = true;
$blackList = array('bot1',

foreach($blackList as $bot){
$agentOK = ( stristr($agent,$bot ) ? true : false;
if(!$agentOK) {
header('Location: http://www.spampoison.com/');

Add "$botCheck= agentCheck();" to the top of each page that you want to screen for bots.

if you want to send empty string agents to spam trap, add 'Not Defined' to the $blackList array.

02-28-2007, 02:21 AM
you should probably be using strpos (http://us2.php.net/manual/en/function.strpos.php)if you just want to check for the occurrence of one string inside of another...

02-28-2007, 02:47 AM
stripos to be more specific. stristr is used for reporting purposes in this function's original context.

02-28-2007, 05:11 AM
I don't suppose this would work then:

if (strstr($_SERVER["HTTP_USER_AGENT"], "Not Defined")) {header("location: http://www.voila.com/");}