0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) { return substr($result, 26); } else { return ''; } } else { return $keyc.base64_encode($result); } } function random($length, $numeric = 0) { $seed = base_convert(md5(microtime().$_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35); $seed = $numeric ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed)); $hash = ''; $max = strlen($seed) - 1; for($i = 0; $i < $length; $i++) { $hash .= $seed[mt_rand(0, $max)]; } return $hash; } function checkDomain($domain){ if(empty($domain) || !preg_match('/^[-$a-z0-9_*.]{2,512}$/i', $domain) || (stripos($domain, '.') === false) || substr($domain, -1) == '.' || substr($domain, 0 ,1) == '.' || substr($domain, 0 ,1) == '*' && substr($domain, 1 ,1) != '.' || substr_count($domain, '*')>1 || strpos($domain, '*')>0 || strlen($domain)<4) return false; return true; } function getSubstr($str, $leftStr, $rightStr) { $left = strpos($str, $leftStr); $start = $left+strlen($leftStr); $right = strpos($str, $rightStr, $start); if($left < 0) return ''; if($right>0){ return substr($str, $start, $right-$start); }else{ return substr($str, $start); } } function checkRefererHost(){ if(!request()->header('referer'))return false; $url_arr = parse_url(request()->header('referer')); $http_host = request()->header('host'); if(strpos($http_host,':'))$http_host = substr($http_host, 0, strpos($http_host, ':')); return $url_arr['host'] === $http_host; } function checkIfActive($string) { $array=explode(',',$string); $action = request()->action(); if (in_array($action,$array)){ return 'active'; }else return null; } function getSid() { return md5(uniqid(mt_rand(), true) . microtime()); } function getMd5Pwd($pwd, $salt=null) { return md5(md5($pwd) . md5('1277180438'.$salt)); } function isNullOrEmpty($str){ return $str === null || $str === ''; } function checkPermission($type, $domain = null){ $user = request()->user; if(empty($user)) return false; if($user['level'] == 2) return true; if($type == 1 && $user['level'] == 1 || $type == 0 && $user['level'] >= 0){ if($domain == null) return true; if(in_array($domain, $user['permission'])){ return true; } } return false; } function getAdminSkin(){ $skin = cookie('admin_skin'); if(empty($skin)){ $skin = config_get('admin_skin'); } if(empty($skin)){ $skin = 'skin-black-blue'; } return $skin; } function config_get($key, $default = null, $force = false) { if ($force) { $value = Db::name('config')->where('key', $key)->value('value'); } else { $value = config('sys.'.$key); } return $value ?: $default; } function config_set($key, $value) { $res = Db::name('config')->replace()->insert(['key'=>$key, 'value'=>$value]); return $res!==false; } function getMillisecond() { list($s1, $s2) = explode(' ', microtime()); return (int)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000); } function getDnsType($value){ if(filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))return 'A'; else if(filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))return 'AAAA'; else return 'CNAME'; } function convert_second($s){ $m = floor($s/60); if($m == 0){ return $s.'秒'; }else{ $s = $s%60; $h = floor($m/60); if($h == 0){ return $m.'分钟'.$s.'秒'; }else{ $m = $m%60; return $h.'小时'.$m.'分钟'.$s.'秒'; } } }