日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

EasyPhp

發(fā)布時間:2023/12/20 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 EasyPhp 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

入口文件

<?php date_default_timezone_set('Asia/Shanghai'); error_reporting(E_ALL ^ E_NOTICE); set_time_limit(300); define("ROOT_PATH" ,dirname(__FILE__)); ini_set("error_log",constant("ROOT_PATH")."/Log/error_log.log"); require_once(ROOT_PATH."/Include/Common.Class.php");

Common.Class.php

<?php require_once("DB.Class.php"); class Common extends DB{function __construct() {parent::__construct();} }$Model=Common::G("Model",Config::$DefaultModel); $Action=Common::G("Action",Config::$DefaultAction); if ($Model!=""){$phpFile = ROOT_PATH."/Model/$Model.class.php";if (is_file($phpFile)){require_once($phpFile);}else{require_once(ROOT_PATH."/404.html");}(New $Model())->$Action(); }

DB.Class.php

<?php require_once("Basic.Class.php"); //網(wǎng)站配置文件 class DB extends Basic{Public $DangerousStringsArr="'|select |insert|update|../|./|\/|delete|/*|* |union|into|load_file|outfile|char(|chr|and |or |eval(|assert|system(|exec(|shell_exec(|passthru|escapeshellcmd|pcntl_exec|file_get_contents|file_put_contents|replace|mysql";function __construct() {parent::__construct();$this->check_request();$this->db();}Function db(){if (!self::$cur_db){self::$cur_db = new PDO("mysql:host=$this->mysql_server_name;dbname=$this->mysql_database", $this->mysql_username, $this->mysql_password,array(PDO::ATTR_PERSISTENT => false));//打開連接self::$cur_db->query("SET NAMES UTF8");}return self::$cur_db;}Function __destruct(){if ($this->db()){}}/*============================================函數(shù)名:page_select_sql作 用:分頁查詢參 數(shù):無返 回:結(jié)果集============================================*/Public Function page_select_sql($sql){$result = $this->db()->query($sql);if ($result){$new_array=array();while( ($row = $result->fetch(PDO::FETCH_ASSOC)) !== false ){$new_array[]=$row;}return $new_array;}else{return false;}}/*============================================函數(shù)名:json_select_sql作 用:查詢SQL輸出JSON數(shù)據(jù)類型.參 數(shù):無返 回:結(jié)果集============================================*/Public Function json_select_sql($sql){$res = $this->page_select_sql($sql);if (is_array($res)){$json = $this->json_encode($res[0],JSON_UNESCAPED_UNICODE);}else{$json = "[]";}return $json;}/*============================================函數(shù)名:select_sql作 用:完成select參 數(shù):無返 回:結(jié)果集============================================*/Public Function select_sql($sql){try {$res=$this->db()->query($sql); //執(zhí)行sql 語句} catch (Exception $e) {die($e->getMessage());}if($res->rowCount()>0){ //獲取語句查詢個數(shù)進(jìn)行判斷反回數(shù)組操作$rs=array();while( ($row=$res->fetch(PDO::FETCH_ASSOC) ) !== false){array_push($rs,$row);}return $rs;}else{return false;}}/*============================================函數(shù)名:mysql_sql作 用:執(zhí)行SQL參 數(shù):無返 回:結(jié)果集============================================*/Public Function mysql_sql($sql){try {$res=$this->db()->query($sql);if ($res){return $res;}else{}} catch (Exception $e) {die($e->getMessage());}return null;}/*============================================函數(shù)名:json_select_sql_all作 用:查詢SQL輸出JSON數(shù)據(jù)類型.參 數(shù):無返 回:結(jié)果集============================================*/Public Function json_select_sql_all($sql){//echo $sql;$res=$this->mysql_sql($sql); //執(zhí)行sql 語句if($res->rowCount()>0){ //獲取語句查詢個數(shù)進(jìn)行判斷反回數(shù)組操作$rs=array();while( ($row=$res->fetch(PDO::FETCH_ASSOC) ) !== false ){array_push($rs,$row);}return $this->json_encode($rs,JSON_UNESCAPED_UNICODE);}else{return "[]";}}Public function json_encode($str,$options = JSON_UNESCAPED_UNICODE) {return urldecode(json_encode($this->url_encode($str),$options));}Public function url_encode($str) {if(is_array($str)) {foreach($str as $key=>$value) {$str[urlencode($key)] = $this->url_encode($value);}} else {$str = urlencode($str);}return $str;}/*============================================函數(shù)名:insert_sql作 用:插入SQL語句參 數(shù):無返 回:成功:ID 失敗:false============================================*/Public Function insert_sql($table,$array) {$sql = "insert into $table (";while( (list($name,$value) = each($array)) !== false ) {$sql .= "$name,";}$sql[strlen($sql)-1] = ')';$sql .= " values (";reset($array);while( (list($name,$value) = each($array)) !== false ) {if(is_string($value)||empty($value))$sql .= "'$value',";else$sql .= "$value,";}$sql[strlen($sql)-1] = ')';$sql .= ";";//echo $sql;if($this->mysql_sql($sql)){return $this->mysql_insert_id();}else{$error=$this->db()->errorInfo();$log=fopen(ROOT_PATH."/Log/insert_sql_error.log","a+");fwrite($log,"sql=$sql error=$error\r\n");fclose($log);return false;}}public Function json_select_sql_table($table,$where = null,$pageIndex = 1,$pageSize = 10,$clos = null,$begin = 0,$order=null){$sql = "SELECT ";if ($clos && is_array($clos) && count($clos) > 0){$closIndex = 0;foreach($clos as $clo){if ($closIndex != 0){$sql .= " , ";}$sql .= " $clo ";$closIndex++;}}else{$sql.=" * ";}$sql.=" FROM `$table` ";if ($where && is_array($where)){$whereIndex = 0;foreach($where as $key => $value){if ($whereIndex == 0){$sql.=" where ";}else{$sql.=" and ";}$sql.= " $key = $value ";$whereIndex++;}}if ($order){if($order && is_array($order) && count($order) > 0){$sql .= " ORDER BY ";$orderIndex = 0;foreach($order as $key => $value){if ($orderIndex != 0){$sql.=" , ";}if (is_numeric($key)){$sql .= $value;$sql .= "ASC ";}else{$sql .= " $key ";$sql .= " $value ";}}}else{$sql .= " ORDER BY ";$sql .= $order;$sql .= " ASC ";}}$pageIndex--;$limitIndex = $pageIndex*$pageSize;$limitIndex+=$begin;$sql .= " LIMIT $limitIndex,$pageSize";return $this->json_select_sql_all($sql);}Public Function mysql_insert_id(){return $this->db()->lastInsertId();}/*============================================函數(shù)名:update_sql作 用:更新SQL語句參 數(shù):無返 回:執(zhí)行結(jié)果============================================*/Public Function update_sql($table,$arr,$where="1=1") {$temparr=Array();if (is_array($arr)){foreach($arr as $n=>$v){if (is_numeric(strpos($n,"=")) && is_numeric($v)){$w=explode("=",$n);$temparr[] = $w[0].'='.$w[1].'+'.$v;}else{if (is_numeric($v) && substr($v,0,1)!="0"){$temparr[]= "$n=$v";}else{$temparr[]= "$n='$v'";}}}$sql = "update $table set ".join(",",$temparr)." where $where";$res=$this->mysql_sql($sql);if($res){return $res;}else{$error=$this->db()->errorInfo();$log=fopen(ROOT_PATH."Log//update_sql_error.log","a+");fwrite($log,"sql=$sql error=$error\r\n");fclose($log);return false;}}else{return false;}}/*============================================函數(shù)名:delete_sql作 用:刪除SQL語句參 數(shù):無返 回:執(zhí)行結(jié)果============================================*/Public Function delete_sql($table,$where="1=1") {$sql = "delete from $table where $where";return $this->mysql_sql($sql);}/*============================================函數(shù)名:execute_sql作 用:執(zhí)行SQL語句參 數(shù):無返 回:執(zhí)行結(jié)果============================================*/Public Function execute_sql($sql){$execute_sql=$this->db()->exec($sql);return $execute_sql;}/*============================================函數(shù)名:count_sql作 用:執(zhí)行SQL語句參 數(shù):無返 回:執(zhí)行結(jié)果============================================*/Public Function count_sql($sql){$result = $this->mysql_sql($sql) or die("{\"error\":\"SQL語句出錯\",\"msg\":\"SQL語句出錯\"}");return $result->rowCount();}/*============================================函數(shù)名:check_request作 用:檢測字符串是否包函危險字符參 數(shù):無返 回:錯誤信息============================================*/Public Function check_request(){$arr=explode("|",$this->DangerousStringsArr);$Action=$_REQUEST;foreach($Action as $key=>$value){foreach($arr as $val){if ($value!='' && is_numeric(strpos(strtolower($value),$val))){//記錄日志$log=fopen(constant("ROOT_PATH")."/Log/sql_injection.log","a+");fwrite($log,"TIME[".date("Y-m-d H:i:s")."] IP[".$this->GetIP()."] REQUEST[".$this->json_encode($_REQUEST,JSON_UNESCAPED_UNICODE)."] USER[".$this->Session("UserName")."] KEY[".$val."]\r\n");fclose($log);exit("{\"error\":\"sql error\",\"msg\":\"非法字符:$val\"}");}}}} }

Basic.Class.php

<?php require_once("Config.Class.php"); //網(wǎng)站配置文件 class Basic extends Config {function __construct() {parent::__construct();!empty($_POST) && $this->antixss($_POST);!empty($_GET) && $this->antixss($_GET);!empty($_COOKIE) && $this->antixss($_COOKIE);!empty($_REQUEST) && $this->antixss($_REQUEST);}/*==================================================函數(shù)名:antixss作 用:防XSS參 數(shù):返 回:==================================================*/Public Function antixss(&$arr) { //'/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',$ra=Array('/script/','/javascript/','/vbscript/','/expression/','/applet/','/meta/','/xml/','/blink/','/link/','/style/','/embed/','/object/','/frame/','/layer/','/bgsound/','/base/','/onload/','/onunload/','/onchange/','/onsubmit/','/onreset/','/onselect/','/onblur/','/onfocus/','/onabort/','/onkeydown/','/onkeypress/','/onkeyup/','/onclick/','/ondblclick/','/onmousedown/','/onmousemove/','/onmouseout/','/onmouseover/','/onmouseup/','/onunload/');if (is_array($arr)){foreach ($arr as $key => $value) {if (!is_array($value)){if (!is_numeric($value)){if (!get_magic_quotes_gpc()) {$value=@addslashes($value);}$value = preg_replace($ra,'',$value);$arr[$key] = @htmlspecialchars(strip_tags($value),ENT_NOQUOTES);}}else{$this->antixss($arr[$key]);}}}}/*==================================================函數(shù)名:ChenkUrl作 用:判斷請求來源參 數(shù):無返 回:成功:True 失敗:False==================================================*/Public Function ChenkUrl(){$rurl=isset($_SERVER["HTTP_REFERER"])?$_SERVER["HTTP_REFERER"]:"";$turl=$_SERVER["SERVER_NAME"];$rurl=str_replace("http://","",$rurl);$rurl=substr($rurl,0,strlen($turl));if ($rurl==$turl || $rurl==""){return true;}else{return false;}}/*==================================================函數(shù)名:Set_Dir作 用:循環(huán)創(chuàng)建目錄參 數(shù):無返 回:成功:True 失敗:False==================================================*/Function Set_Dir($dir, $mode = 0755){if (is_dir(iconv('utf-8', 'gbk', $dir))){return false;}else{if(mkdir(iconv('utf-8', 'gbk', $dir),$mode,true)){return true;}else{return false;}}}/*==================================================函數(shù)名:Save_File作 用:保存文件參 數(shù):無返 回:成功:True 失敗:False==================================================*/Function Save_File($content,$dir){$dir=str_replace("\\","/",$dir);$dir=str_replace("//","/",$dir);$filename=$dir;$arr=explode("/",$dir);$path=str_replace(end($arr),"",$dir);$path=ltrim($path,"/");$path=rtrim($path,"/");if ($path!=""){$this->Set_Dir($path,0);}if (file_put_contents(iconv('utf-8', 'gbk',$filename),$content)){return true;}else{return false;}}/*==================================================函數(shù)名:Arr_To_Json作 用:將數(shù)組轉(zhuǎn)換為JSON參 數(shù):無返 回:成功:True 失敗:False==================================================*/function Arr_To_Json($arr){return json_encode($arr,JSON_UNESCAPED_UNICODE);}/*==================================================函數(shù)名:Json_To_Arr作 用:將JSON轉(zhuǎn)換為數(shù)組參 數(shù):無返 回:成功:True 失敗:False==================================================*/function Json_To_Arr($json){return json_decode($json,true);}/*==================================================函數(shù)名:Arr_Arr作 用:判斷兩個數(shù)組是否完全相等參 數(shù):無返 回:成功:True 失敗:False==================================================*/function Arr_Arr($arr1,$arr2){if(json_encode($arr1,JSON_UNESCAPED_UNICODE)==json_encode($arr2,JSON_UNESCAPED_UNICODE)){return true;}else{return false;}}/*==================================================函數(shù)名:InStr作 用:判斷某個字符是否在字符串中參 數(shù):無返 回:成功:True 失敗:False==================================================*/Public Function InStr($s,$v){//if (empty($s) || empty($v)){return false;}if (strpos($s,$v)===false){return false;}else{return true;}}/*==================================================函數(shù)名:utf8_strlen作 用:PHP獲取字符串長度,中文標(biāo)點或者中文漢字算一個字符參 數(shù):要獲取的字符串.返 回:字符串長度==================================================*/Public function utf8_strlen($string = null) {preg_match_all("/./us", $string, $match); // 將字符串分解為單元return count($match[0]); // 返回單元個數(shù)}/*==================================================函數(shù)名:array_sort作 用:給定的二維數(shù)組按照指定的鍵值進(jìn)行排序參 數(shù):返 回:==================================================*/Public function array_sort($arr,$keys,$type='asc'){$keysvalue = $new_array = array();foreach ($arr as $k=>$v){$keysvalue[$k] = $v[$keys];}if($type == 'asc'){asort($keysvalue);}else{arsort($keysvalue);}reset($keysvalue);foreach ($keysvalue as $k=>$v){$new_array[$k] = $arr[$k];}return $new_array;}/*============================================函數(shù)名:Session作 用:操作SESSION參 數(shù):當(dāng)沒有參數(shù)時:返回全部seesion,一個時:為讀取,二個時:為設(shè)置.返 回:相關(guān)數(shù)據(jù).============================================*/Public Function Session(){$args = func_get_args();session_start();$key = $args[0];if (count($args) == 2){$_SESSION[$key]=$args[1];$re = $args[1];}else if(count($args) == 1){if (isset($_SESSION[$key])){$re = $_SESSION[$key];}else{$re = null;}}else{$re = $_SESSION;}session_write_close();return $re;}/*==================================================函數(shù)名:HtmlToStr作 用:HTML轉(zhuǎn)字符串參 數(shù):無返 回:成功:True 失敗:False==================================================*/Public Function HtmlToStr($str){if (!empty($str) && !is_numeric($str)){return htmlspecialchars($str);}else{return $str;}}/*============================================函數(shù)名:G作 用:獲取提交參數(shù)參 數(shù):$n:參數(shù)名返 回:獲取的值============================================*/static Public Function G($n,$t=null){$arr=$_REQUEST;if (array_key_exists($n,$arr)){$v=$arr[$n];if ($v==""){$res=$v;}else{$res=$v;}return $res;}else{return $t;}}/*============================================函數(shù)名:C作 用:獲取Cookies參 數(shù):$n:參數(shù)名返 回:獲取的值============================================*/Public Function C($n){return $_COOKIE[$n];}/*============================================函數(shù)名:IsArrayStr作 用:檢查數(shù)組中是否存在該字符串參 數(shù): str:被檢查的字符串 Arr:被檢查的數(shù)組返 回:成功:True 失敗:False VarType============================================*/Public function IsArrayStr($arr,$str){$result = false;foreach($arr as $key){if($key==$str){$result = true;break;}}return $result;}/*============================================函數(shù)名:get_http_page作 用:獲取網(wǎng)頁http代碼參 數(shù):Url:地址 Cset:編碼返 回:成功:網(wǎng)頁http代碼 失敗:False============================================*/Public Function get_http_page($url,$method="GET",$iconv=false,$timeout=10){if ($url==""){return false;}$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);if ($method=='POST'){curl_setopt($ch,CURLOPT_POST,1);}curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);curl_setopt($ch, CURLOPT_HEADER, false); //設(shè)定是否顯示頭信息curl_setopt($ch, CURLOPT_NOBODY, false); //設(shè)定是否輸出頁面內(nèi)容$return = curl_exec($ch);curl_close($ch);if (!$return){ //如果使用上面方式未采集成功,則使用另一種方式采集.$opts = array('http' =>array('method' => $method,'timeout' => $timeout));$return = file_get_contents($url,false,stream_context_create($opts),-1,40000);}if ($iconv){$return = iconv("utf-8","gb2312",$return);}return $return;}/*============================================函數(shù)名:get_sub_content作 用:截取字符串中的某部分代碼參 數(shù):body:內(nèi)容返 回:截取后的字符串============================================*/Public function get_sub_content($str,$start,$end){$str = explode($start, $str);$str = explode($end, $str[1]);return $str[0];}/*==================================================函數(shù)名:GetIP作 用:取得用戶IP參 數(shù):無返 回:訪問者IP==================================================*/Public Function GetIP(){if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))$ip = getenv("HTTP_CLIENT_IP");else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))$ip = getenv("HTTP_X_FORWARDED_FOR");else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))$ip = getenv("REMOTE_ADDR");else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))$ip = $_SERVER['REMOTE_ADDR'];else$ip = "unknown";return($ip);}/*==================================================函數(shù)名:getbrowser作 用:獲取用戶瀏覽器版本參 數(shù):返 回:無==================================================*/function getbrowser() {global $_SERVER;$agent = $_SERVER['HTTP_USER_AGENT'];$browser = '';$browser_ver = '';if (preg_match('/OmniWeb\/(v*)([^\s|;]+)/i', $agent, $regs)) {$browser = 'OmniWeb';$browser_ver = $regs[2];}if (preg_match('/Netscape([\d]*)\/([^\s]+)/i', $agent, $regs)) {$browser = 'Netscape';$browser_ver = $regs[2];}if (preg_match('/safari\/([^\s]+)/i', $agent, $regs)) {$browser = 'Safari';$browser_ver = $regs[1];}if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)) {$browser = 'Internet Explorer';$browser_ver = $regs[1];}if (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs)) {$browser = 'Opera';$browser_ver = $regs[1];}if (preg_match('/NetCaptor\s([^\s|;]+)/i', $agent, $regs)) {$browser = '(Internet Explorer ' .$browser_ver. ') NetCaptor';$browser_ver = $regs[1];}if (preg_match('/Maxthon/i', $agent, $regs)) {$browser = '(Internet Explorer ' .$browser_ver. ') Maxthon';$browser_ver = '';}if (preg_match('/360SE/i', $agent, $regs)) {$browser = '(Internet Explorer ' .$browser_ver. ') 360SE';$browser_ver = '';}if (preg_match('/SE 2.x/i', $agent, $regs)) {$browser = '(Internet Explorer ' .$browser_ver. ') 搜狗';$browser_ver = '';}if (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)) {$browser = 'FireFox';$browser_ver = $regs[1];}if (preg_match('/Lynx\/([^\s]+)/i', $agent, $regs)) {$browser = 'Lynx';$browser_ver = $regs[1];}if ($browser != '') {return $browser.' '.$browser_ver;}else {return 'Unknow browser';}}/*==================================================函數(shù)名:getplat作 用:獲取系統(tǒng)版本參 數(shù):返 回:無==================================================*/function getplat() {if ($this->isMobile()){return "Mobile";}global $_SERVER;$agent = strtolower($_SERVER['HTTP_USER_AGENT']);$os = false;if (preg_match('/win/', $agent)) {if (preg_match('/4.9/', $agent)) {$os="Windows ME";}if (preg_match('/nt 5.0/', $agent)) {$os="Windows 2000";}if (preg_match('/nt 5.1/', $agent)) {$os="Windows XP";}if (preg_match('/nt 5.2/', $agent)) {$os="Windows Server 2003";}if (preg_match('/nt 6.0/', $agent)) {$os="Windows Vista/Server 2008";}if (preg_match('/nt 6.1/', $agent)) {$os="Windows 7/Server 2008 R2/Thin PC";}if (preg_match('/nt 6.2/', $agent)) {$os="Windows 8/Server 2012";}if (preg_match('/nt 6.3/', $agent)) {$os="Windows 8.1/Server 2012 R2";}if ($os==""){$os="Windows";}if (preg_match('/wow64/', $agent)) {$os.=" (64位系統(tǒng))";}} else if (preg_match('/linux/', $agent)) {$os = 'Linux';} else if (preg_match('/unix/', $agent)) {$os = 'Unix';} else if (preg_match('/sun/', $agent) && preg_match('/os/', $agent)) {$os = 'SunOS';} else if (preg_match('/ibm/', $agent) && preg_match('/os/', $agent)) {$os = 'IBM OS/2';} else if (preg_match('/mac/', $agent) && preg_match('/pc/', $agent)) {$os = 'Macintosh';} else if (preg_match('/powerpc/', $agent)) {$os = 'PowerPC';} else if (preg_match('/aix/', $agent)) {$os = 'AIX';} else if (preg_match('/hpux/', $agent)) {$os = 'HPUX';} else if (preg_match('/netbsd/', $agent)) {$os = 'NetBSD';} else if (preg_match('/bsd/', $agent)) {$os = 'BSD';} else if (preg_match('/osf1/', $agent)) {$os = 'OSF1';} else if (preg_match('/irix/', $agent)) {$os = 'IRIX';} else if (preg_match('/freebsd/', $agent)) {$os = 'FreeBSD';} else if (preg_match('/teleport/', $agent)) {$os = 'teleport';} else if (preg_match('/flashget/', $agent)) {$os = 'flashget';} else if (preg_match('/webzip/', $agent)) {$os = 'webzip';} else if (preg_match('/offline/', $agent)) {$os = 'offline';} else{$os = $agent;}return $os;}/*==================================================函數(shù)名:isMobile作 用:判斷是否為手機(jī)登陸參 數(shù):返 回:無==================================================*/function isMobile() {if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])){return true;} // 如果有HTTP_X_WAP_PROFILE則一定是移動設(shè)備if (isset ($_SERVER['HTTP_VIA'])) {return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;} //如果via信息含有wap則一定是移動設(shè)備,部分服務(wù)商會屏蔽該信息 找不到為flase,否則為trueif (isset ($_SERVER['HTTP_USER_AGENT'])) { //判斷手機(jī)發(fā)送的客戶端標(biāo)志,兼容性有待提高$clientkeywords = array ('nokia','sony','ericsson','mot','samsung','htc','sgh','lg','sharp','sie-','philips','panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile');if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {return true;} // 從HTTP_USER_AGENT中查找手機(jī)瀏覽器的關(guān)鍵字}//協(xié)議法,因為有可能不準(zhǔn)確,放到最后判斷if (isset ($_SERVER['HTTP_ACCEPT'])) {// 如果只支持wml并且不支持html那一定是移動設(shè)備 如果支持wml和html但是wml在html之前則是移動設(shè)備if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {return true;}}return false;}/*==================================================函數(shù)名:is_class_obj作 用:檢查CLASS里是否存在對象參 數(shù):classname:類名,obj:要查找的對象名返 回:存在:true,否則:false==================================================*/Public Function is_class_obj($classname,$obj){if ($obj==""){return true;}$result = false;$class_methods = get_class_methods("$classname");foreach ($class_methods as $method_name) {if($method_name==$obj){$result = true;break;}}return $result;}/*==================================================函數(shù)名:DateDiff作 用:參 數(shù):返 回:==================================================*/Public Function DateDiff($part, $begin, $end){$diff = strtotime($end) - strtotime($begin);$retval = null;switch($part){case "y": $retval = bcdiv($diff, (60 * 60 * 24 * 365)); break;case "m": $retval = bcdiv($diff, (60 * 60 * 24 * 30)); break;case "w": $retval = bcdiv($diff, (60 * 60 * 24 * 7)); break;case "d": $retval = bcdiv($diff, (60 * 60 * 24)); break;case "h": $retval = bcdiv($diff, (60 * 60)); break;case "n": $retval = bcdiv($diff, 60); break;case "s": $retval = $diff; break;}return intval($retval);}/*==================================================函數(shù)名:getBetweenTwoDate作 用:參 數(shù):返 回:==================================================*/Public Function getBetweenTwoDate($date1,$date2){$Date_List_a1=explode("-",explode(" ",$date1)[0]);$Date_List_a2=explode("-",explode(" ",$date2)[0]);$d1=mktime(0,0,0,$Date_List_a1[1],$Date_List_a1[2],$Date_List_a1[0]);$d2=mktime(0,0,0,$Date_List_a2[1],$Date_List_a2[2],$Date_List_a2[0]);$Days=round(($d1-$d2)/3600/24);return $Days;}/*==================================================函數(shù)名:DateDiff作 用:參 數(shù):返 回:==================================================*/Public Function DateAdd($part, $n, $date,$t=0){$val = null;switch($part){case "y": $val = date("Y-m-d H:i:s", strtotime($date ." +$n year")); break;case "m": $val = date("Y-m-d H:i:s", strtotime($date ." +$n month")); break;case "w": $val = date("Y-m-d H:i:s", strtotime($date ." +$n week")); break;case "d": $val = date("Y-m-d H:i:s", strtotime($date ." +$n day")); break;case "h": $val = date("Y-m-d H:i:s", strtotime($date ." +$n hour")); break;case "n": $val = date("Y-m-d H:i:s", strtotime($date ." +$n minute")); break;case "s": $val = date("Y-m-d H:i:s", strtotime($date ." +$n second")); break;}if ($t==1){return explode(" ",$val)[0];}else{return $val;}}/*==================================================函數(shù)名:is_date作 用:參 數(shù):返 回:==================================================*/Public Function is_date($date){if(preg_match("/^[0-9]{4}(\-|\/)[0-9]{1,2}(\\1)[0-9]{1,2}(|\s+[0-9]{1,2}(|:[0-9]{1,2}(|:[0-9]{1,2})))$/",$date)) {return true;}else{return false;}}/*==================================================函數(shù)名:strToHex作 用:加密函數(shù)參 數(shù):返 回:==================================================*/Public Function strToHex($string,$pass=""){$hex="";for ($i=0;$i<strlen($string);$i++){$hex.=dechex(ord($string[$i]));}$passstr="";for ($i=0;$i<strlen($pass);$i++){$passstr.=dechex(ord($pass[$i]));}return strtoupper($hex.$passstr);}/*==================================================函數(shù)名:HexToStr作 用:公共函數(shù)定義參 數(shù):返 回:==================================================*/Public Function HexToStr($hex,$pass=""){$string="";for ($i=0;$i<strlen($hex)-1;$i+=2){$string.=chr(hexdec($hex[$i].$hex[$i+1]));}if ($pass!=""){$string=str_replace($pass,"",$string);}return $string;}/*==================================================函數(shù)名:DelDir作 用:刪除目錄即當(dāng)前文件夾參 數(shù):返 回:==================================================*/Public Function DelDir($dir) {$dh=opendir($dir); //先刪除目錄下的文件while ( ($file=readdir($dh)) !== false ) {if($file!="." && $file!="..") {$fullpath=$dir."/".$file;if(!is_dir($fullpath)) {@unlink($fullpath);} else {@rmdir($fullpath);//“@”抑制住錯誤顯示}}}closedir($dh);if(@rmdir($dir)) { //刪除當(dāng)前文件夾return true;} else {return false;}}/*==================================================函數(shù)名:unescape作 用:unescape解碼參 數(shù):返 回:==================================================*/Public function unescape($str){$ret = '';$len = strlen($str);for ($i = 0; $i < $len; $i++){if ($str[$i] == '%' && $str[$i+1] == 'u'){$val = hexdec(substr($str, $i+2, 4));if ($val < 0x7f){$ret .= chr($val);}else if($val < 0x800){$ret .= chr(0xc0|($val>>6)).chr(0x80|($val&0x3f));}else {$ret .= chr(0xe0|($val>>12)).chr(0x80|(($val>>6)&0x3f)).chr(0x80|($val&0x3f));}$i += 5;}else if ($str[$i] == '%'){$ret .= urldecode(substr($str, $i, 3));$i += 2;}else{$ret .= $str[$i];}}return $ret;} }

Config.Class.php

<?php class Config{Public $mysql_server_name ='127.0.0.1'; //localhostPublic $mysql_username ='root'; //登陸賬戶Public $mysql_password ='root'; //連接密碼Public $mysql_database ='easy'; //數(shù)據(jù)庫名字static Public $DefaultModel = 'Error';static Public $DefaultAction = 'Index';static public $cur_db;function __construct() {} }

functions.php

<?php /*** 獲取和設(shè)置語言定義(不區(qū)分大小寫)* @param string|array $name 語言變量* @param mixed $value 語言值或者變量* @return mixed*/ function L($name=null, $value=null) {static $_lang = array();// 空參數(shù)返回所有定義if (empty($name))return $_lang;// 判斷語言獲取(或設(shè)置)// 若不存在,直接返回全大寫$nameif (is_string($name)) {$name = strtoupper($name);if (is_null($value)){return isset($_lang[$name]) ? $_lang[$name] : $name;}elseif(is_array($value)){// 支持變量$replace = array_keys($value);foreach($replace as &$v){$v = '{$'.$v.'}';}return str_replace($replace,$value,isset($_lang[$name]) ? $_lang[$name] : $name);}$_lang[$name] = $value; // 語言定義return null;}// 批量定義if (is_array($name))$_lang = array_merge($_lang, array_change_key_case($name, CASE_UPPER));return null; }

使用示例
Novel.class.php

<? Class Novel extends Common{function __construct() {parent::__construct();header("Content-type: text/html; charset=utf-8");}Public Function Index(){}public function htmtocode($content){$content = str_replace("\r\n","\\r\\n",$content);return $content;}public Function Show($result="\"{}\"",$resultName="result",$msg="\"ok\"",$msgName = "msg"){$jsonp = $this->G("cb");if ($jsonp == null){echo "{\"$msgName\": $msg,\"$resultName\":$result}";}else{echo $this->htmtocode($jsonp."("."{\"$msgName\": $msg,\"$resultName\":$result}".")");}}//http://localhost/?Model=Novel&Action=NovelList//小說列表Public Function NovelList(){$page = $this->G("page",1);$pageSize = $this->G("pageSize",10);$begin = ($page-1) * $pageSize;$sql_s = "SELECT novel.id,novel.`name`,novel.intro,GROUP_CONCAT(novel_config.id) as config_id FROM novel INNER JOIN novel_config ON novel.id = novel_config.novel_id GROUP BY novel.id LIMIT $begin, $pageSize";$this->Show($this->json_select_sql_all($sql_s),"novel_list");}//http://localhost/?Model=Novel&Action=ChapterList&novel_id=1&novel_config_id=1//小說章節(jié)列表Public Function ChapterList(){$novel_id = $this->G("novel_id");$novel_config_id = $this->G("novel_config_id",null);$where = array('novel_id'=>$novel_id);if ($novel_config_id){$where["novel_config_id"] = $novel_config_id;}$pageIndex = $this->G("pageIndex",0);$page = $this->G("page",1);if ($page != 0 && $pageIndex == 0) {$pageIndex = $page ;}$pageSize = $this->G("pageSize",10);$count = $this->G("count",0);$this->Show($this->json_select_sql_table("novel_list",$where,$pageIndex,$pageSize,array("id","novel_id","content_index","title","novel_config_id"),$count,"content_index"),"chapter_list");}//http://localhost/?Model=Novel&Action=ChapterContent&id=7315//小說章節(jié)內(nèi)容Public Function ChapterContent(){$id = $this->G("id");if ($id){$where = array();$where['id'] = $id;$this->Show($this->json_select_sql_table("novel_list",$where),"chapter_content");}else{$novel_id = $this->G("novel_id");$novel_config_id = $this->G("novel_config_id");$content_index = $this->G("content_index");if ($novel_id && $novel_config_id && $content_index){$where = array();$where['novel_id'] = $novel_id;$where['novel_config_id'] = $novel_config_id;$where['content_index'] = $content_index;$this->Show($this->json_select_sql_table("novel_list",$where),"chapter_content");}}}//?Model=Novel&Action=NovelListLastInfo&ids=1,2,3&config_ids=1,2,3public Function NovelListLastInfo(){$ids = $this->G("ids");$config_ids = $this->G("config_ids");$sql = "select id,novel_id,content_index,title,novel_config_id from (select id,novel_id,content_index,title,novel_config_id from novel_list where novel_id in ($ids) and novel_config_id in ($config_ids) order by content_index desc ) a group by novel_id";$this->Show($this->json_select_sql_all($sql));}Public Function EasySpider(){//system(ROOT_PATH."/Debug/EasySpider.exe");}Public Function NoveCover(){$novel_id = $this->G("novel_id");$id = $this->G("id");if (!$novel_id){$novel_id = $id;}$sql = "SELECT IF( (SELECT COUNT(*) FROM novel_img where novel_id = '$novel_id') > 0 ,(SELECT img from novel_img where novel_id = '$novel_id'),(SELECT img from novel_img where novel_id = '0')) as img";header('Content-type: image/jpg');$res = $this->mysql_sql($sql);if($res->rowCount()>0){while( ($row=$res->fetch(PDO::FETCH_ASSOC) ) !== false){echo ($row['img']);break;}}}}

總結(jié)

以上是生活随笔為你收集整理的EasyPhp的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。