URL、表單資料、IP等處理類,url表單_PHP教程

來源:互聯網
上載者:User

URL、表單資料、IP等處理類,url表單


phpclass ev{    public $cookie;    public $post;    public $get;    public $file;    public $url;    public $G;    private $e;    public function __construct()    {if (ini_get('magic_quotes_gpc')) {  //判斷php.ini是否有magic_quotes_gpc過濾(轉義)函數            $get    = $this->stripSlashes($_REQUEST);            $post   = $this->stripSlashes($_POST);            $this->cookie = $this->stripSlashes($_COOKIE);        } else {            $get    = $_REQUEST;            $post   = $_POST;            $this->cookie = $_COOKIE;        }        $this->file = $_FILES;        $this->get = $this->initData($get);        $this->post = $this->initData($post);        $this->url = $this->parseUrl();        $this->cookie = $this->initData($this->cookie);    }    //解析url    public function parseUrl()    {        if(isset($_REQUEST['route']))        {            return explode('-',$_REQUEST['route']);  //解析路由        }        elseif(isset($_SERVER['QUERY_STRING']))        {            $tmp = explode('#',$_SERVER['QUERY_STRING'],2);            $tp = explode('&',$tmp[0],2);            return explode('-',$tp[0]);        }        else return false;    }    //返回$_REQUEST數組內的值    public function get($par)    {        if(isset($this->get[$par]))return $this->get[$par];        else return false;    }    //返回$_POST數組內的值    public function post($par)    {        if(isset($this->post[$par]))return $this->post[$par];        else return false;    }    //返回URL數組中的值    public function url($par)    {        $par = intval($par);        if(isset($this->url[$par]))return $this->url[$par];        else return false;    }    //設定COOKIE    public function setCookie($name,$value,$time=3600)    {        if($time)$time = TIME + $time;        else $time = 0;        if(CDO)setCookie(CH.$name,$value,$time,CP,CDO);        else setCookie(CH.$name,$value,$time,CP);    }    //擷取cookie    public function getCookie($par,$nohead = 0)    {        if(isset($this->cookie[CH.$par]))return $this->cookie[CH.$par];        elseif(isset($this->cookie[$par]) && $nohead)return $this->cookie[$par];        else return false;    }    //擷取$_FILE    public function getFile($par)    {        if(isset($this->file[$par]))return $this->file[$par];        else return false;    }    //初始化資料    public function initData($data)    {        if(is_array($data))        {            foreach($data as $key => $value)            {                if($this->strings->isAllowKey($key) === false)                {                    unset($data[$key]);                }                else                $data[$key] = $this->initData($value);            }            return $data;        }        else        {            if(is_numeric($data))            {                if($data[0] === 0)return $this->addSlashes(htmlspecialchars(str_replace("'","'",$data)));                if(strlen($data) >= 11)return $this->addSlashes(htmlspecialchars(str_replace("'","'",$data)));                if(strpos($data,'.'))return floatval($data);                else return intval($data);            }            if(is_string($data))return $this->addSlashes(htmlspecialchars(str_replace("'","'",$data)));            if(is_bool($data))return (bool)$data;            return false;        }    }    //去除逸出字元    public function stripSlashes($data)    {        if (is_array($data)) {              foreach ($data as $key => $value) {                $data[$key] = $this->stripSlashes($value);              }        } else {              $data = stripSlashes(trim($data));        }        return $data;    }    //添加逸出字元    public function addSlashes($data)    {        if (is_array($data)) {              foreach ($data as $key => $value) {                $data[$key] = $this->addSlashes($value);              }        } else {              $data = addSlashes(trim($data));        }        return $data;    }    //擷取用戶端IP    public function getClientIp()    {        if(!isset($this->e['ip']))        {            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";            $this->e['ip'] = $ip;        }        return $this->e['ip'];    }    //根據次層網域擷取資訊    public function getSecondDomain()    {        $domain = $_SERVER['HTTP_HOST'];        $domain = str_replace(array('com.cn','net.cn','gov.cn','org.cn'),'com',$domain);        $tmp = explode('.',$domain);        if(count($tmp) < 3)return false;        elseif(is_numeric($tmp[0]))return false;        else return $tmp[0];    }}?>

http://www.bkjia.com/PHPjc/1115244.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1115244.htmlTechArticleURL、表單資料、IP等處理類,url表單 ? php class ev{ public $cookie; public $post; public $ get ; public $file; public $url; public $G; private $e; public function __con...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.