Jump to content

strstr


otuatail

Recommended Posts

Ok but first. I want to log webrobots in a database and also prevent them from increasing the hit counter. Yes there are a lot out there and I can't stop the obscure ones.

 

config.inc

Define (MSNBOT,  "msnbot");

 

functions.inc

function isRobot($browser)

{

  $Robot = "0";

  if(strpos($browser, YAHOO))

    $Robot = "1";

  if(strpos($browser, HOUXOU))

    $Robot = "1";

  if(strpos($browser, MSNBOT))

    $Robot = "1";

return $Robot;

}

 

this is the calling routine.

$_SESSION['K9'] = isRobot($_SERVER["HTTP_USER_AGENT"]);

 

But the agent for msn is.

msnbot/1.0 (+http://search.msn.com/msnbot.htm)

if change the define (removing the first letter) to

Define (MSNBOT,  "snbot");

WORKS FINE.

 

Link to comment
https://forums.phpfreaks.com/topic/49825-strstr/#findComment-244400
Share on other sites

Can someone tell me the numerical error code for error. I have uncovered a problem in code. stsstr(haystack, needle).  If the search string is at the very begining. that in 'C' is zero haystack[0]

this is a fail. any way around this.

 

Desmond.

 

I think you are talking about strpos() as opposed to strstr() strstr does not have that problem, with strpos you need to do the following

 

if (strpos($haystack, $needle) !== false) {

//character was found

}

Link to comment
https://forums.phpfreaks.com/topic/49825-strstr/#findComment-244401
Share on other sites

you can use my function if you want... its a little more... big...

 

<?
function get_mybrowser(){
if(strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko')){
  if(strpos($_SERVER['HTTP_USER_AGENT'], 'Netscape')) return 'netscape';
  elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox')) return 'firefox';
  else return 'mozilla';
}elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')){
  if(strpos($_SERVER['HTTP_USER_AGENT'], 'Opera')) return 'opera';
  else return 'ie';
}else return 'other';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/49825-strstr/#findComment-244407
Share on other sites

Ok thanks. I tried to find a function prototype here. but is false -1 or 0 ?

 

Desmond.

 

believe it or not but -1 is actually a true value, zero is interpreted as false but to get back to the context of what i was saying.

 

if (strpos() !== false);

 

the above code uses !== this is different to !=, it means it has to be false, not 0, not -1, but false. The function strpos() returns false on failure and zero if the character is the first character, if you dont get my poorly typed explanation just look up  === and !== on php.net

Link to comment
https://forums.phpfreaks.com/topic/49825-strstr/#findComment-244411
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.