function core分析
function dstrpos($string, $arr, $returnvalue = false) { if(empty($string)) return false; // 做检测 是否为空 foreach((array)$arr as $v) { if(strpos($string, $v) !== false) { $return = $returnvalue ? $v : true; return $return; } } return false; }
三个参数 被检测的string, 是否在其中的arr, 是否返回其值 和 true false。
function checkrobot($useragent = '') { static $kw_spiders = array('bot', 'crawl', 'spider' ,'slurp', 'sohu-search', 'lycos', 'robozilla'); static $kw_browsers = array('msie', 'netscape', 'opera', 'konqueror', 'mozilla'); $useragent = strtolower(empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent); if(strpos($useragent, 'http://') === false && dstrpos($useragent, $kw_browsers)) return false; if(dstrpos($useragent, $kw_spiders)) return true; return false; }
检测是否是机器人访问
function dstripslashes($string) { if(empty($string)) return $string; if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = dstripslashes($val); } } else { $string = stripslashes($string); } return $string; }
去除转义字符
function daddslashes($string, $force = 1) { if(is_array($string)) { $keys = array_keys($string); foreach($keys as $key) { $val = $string[$key]; unset($string[$key]); $string[addslashes($key)] = daddslashes($val, $force); } } else { $string = addslashes($string); } return $string; }
添加转义字符
function dsetcookie($var, $value = '', $life = 0, $prefix = 1, $httponly = false) { global $_G; $config = $_G['config']['cookie']; $_G['cookie'][$var] = $value; $var = ($prefix ? $config['cookiepre'] : '').$var; $_COOKIE[$var] = $value; if($value == '' || $life < 0) { $value = ''; $life = -1; } if(defined('IN_MOBILE')) { $httponly = false; } $life = $life > 0 ? getglobal('timestamp') + $life : ($life < 0 ? getglobal('timestamp') - 31536000 : 0); $path = $httponly && PHP_VERSION < '5.2.0' ? $config['cookiepath'].'; HttpOnly' : $config['cookiepath']; $secure = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0; if(PHP_VERSION < '5.2.0') { setcookie($var, $value, $life, $path, $config['cookiedomain'], $secure); } else { setcookie($var, $value, $life, $path, $config['cookiedomain'], $secure, $httponly); } }
设置cookie
function getglobal($key, $group = null) { global $_G; $key = explode('/', $group === null ? $key : $group.'/'.$key); $v = &$_G; foreach ($key as $k) { if (!isset($v[$k])) { return null; } $v = &$v[$k]; } return $v; }
获取$_G中变量
function setglobal($key , $value, $group = null) { global $_G; $key = explode('/', $group === null ? $key : $group.'/'.$key); $p = &$_G; foreach ($key as $k) { if(!isset($p[$k]) || !is_array($p[$k])) { $p[$k] = array(); } $p = &$p[$k]; } $p = $value; return true; }
设置$_G变量属性
function libfile($libname, $folder = '') { $libpath = '/source/'.$folder; if(strstr($libname, '/')) { list($pre, $name) = explode('/', $libname); $path = "{$libpath}/{$pre}/{$pre}_{$name}"; } else { $path = "{$libpath}/{$libname}"; } return preg_match('/^[\w\d\/_]+$/i', $path) ? realpath(DISCUZ_ROOT.$path.'.php') : false; }
加载source下面文件
凡不能毁灭我的,将使我更强大。