otuatail Posted May 3, 2007 Share Posted May 3, 2007 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. Quote Link to comment Share on other sites More sharing options...
papaface Posted May 3, 2007 Share Posted May 3, 2007 Ignore Quote Link to comment Share on other sites More sharing options...
taith Posted May 3, 2007 Share Posted May 3, 2007 ?ignore? can we se some code? Quote Link to comment Share on other sites More sharing options...
otuatail Posted May 3, 2007 Author Share Posted May 3, 2007 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. Quote Link to comment Share on other sites More sharing options...
Nameless12 Posted May 3, 2007 Share Posted May 3, 2007 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 } Quote Link to comment Share on other sites More sharing options...
papaface Posted May 3, 2007 Share Posted May 3, 2007 ?ignore? I said something wrong, so my post was worthless. Quote Link to comment Share on other sites More sharing options...
otuatail Posted May 3, 2007 Author Share Posted May 3, 2007 Ok thanks. I tried to find a function prototype here. but is false -1 or 0 ? Desmond. Quote Link to comment Share on other sites More sharing options...
taith Posted May 3, 2007 Share Posted May 3, 2007 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'; } ?> Quote Link to comment Share on other sites More sharing options...
Nameless12 Posted May 3, 2007 Share Posted May 3, 2007 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 Quote Link to comment Share on other sites More sharing options...
otuatail Posted May 3, 2007 Author Share Posted May 3, 2007 Ok thanks that makes sense. It works. Thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.