class cls_CoreFunc
{
public static function func_CheckRobot($str_useragent = '')
{
private static $str_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
private static $str_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla'; $str_useragent = empty($str_useragent) ? $_SERVER['HTTP_USER_AGENT'] : $str_useragent; if(!self::func_strexists($str_useragent, 'http://') && preg_match("/($str_browsers)/i", $str_useragent)) {
return false;
} elseif(preg_match("/($str_spiders)/i", $str_useragent)) {
return true;
} else {
return false;
}
} public static function func_strexists($str_string, $str_find)
{
return !(strpos($str_string, $str_find) === FALSE);
}
}
这段代码有错误,问题就出在将$str_spiders 和 $str_browsers设为私有静态变量
如果我想将$str_spiders 和 $str_browsers设为私有静态变量,该怎么做呢
{
public static function func_CheckRobot($str_useragent = '')
{
private static $str_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
private static $str_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla'; $str_useragent = empty($str_useragent) ? $_SERVER['HTTP_USER_AGENT'] : $str_useragent; if(!self::func_strexists($str_useragent, 'http://') && preg_match("/($str_browsers)/i", $str_useragent)) {
return false;
} elseif(preg_match("/($str_spiders)/i", $str_useragent)) {
return true;
} else {
return false;
}
} public static function func_strexists($str_string, $str_find)
{
return !(strpos($str_string, $str_find) === FALSE);
}
}
这段代码有错误,问题就出在将$str_spiders 和 $str_browsers设为私有静态变量
如果我想将$str_spiders 和 $str_browsers设为私有静态变量,该怎么做呢
{
private static $str_spiders;
private static $str_browsers;
public static function func_CheckRobot($str_useragent = '')
{
$this->$str_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
$this->$str_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla'; $str_useragent = empty($str_useragent) ? $_SERVER['HTTP_USER_AGENT'] : $str_useragent; if(!self::func_strexists($str_useragent, 'http://') && preg_match("/($str_browsers)/i", $str_useragent)) {
return false;
} elseif(preg_match("/($str_spiders)/i", $str_useragent)) {
return true;
} else {
return false;
}
} public static function func_strexists($str_string, $str_find)
{
return !(strpos($str_string, $str_find) === FALSE);
}
}
class cls_CoreFunc
{
private static $str_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
private static $str_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';//成员变量
public static function func_CheckRobot($str_useragent = '')
{
……
……
……
去掉private static就可以了。
一针见血!!