php如何獲得手機端的手機號碼以及ip地址(代碼執行個體)

來源:互聯網
上載者:User

本篇文章給大家帶來的內容是關於php如何獲得手機端的手機號碼以及ip地址 ,有一定的參考價值,有需要的朋友可以參考一下,希望對你有所協助。

<?php/** * Created by PhpStorm. * User: liubao * Date: 2018/8/30 * Time: 16:21 *//** *   類名:   mobile *   描述:   手機資訊類 *   其他:   偶然   編寫 */class   mobile{    /**     *   函數名稱:   getPhoneNumber     *   函數功能:   取手機號     *   輸入參數:   none     *   函數傳回值:   成功返回號碼,失敗返回false     *   其它說明:   說明     */    function getPhoneNumber()    {        if (isset($_SERVER['HTTP_X_NETWORK_INFO '])) {            $str1 = $_SERVER['HTTP_X_NETWORK_INFO '];            $getstr1 = preg_replace('/(.*,)(11[d])(,.*)/i ', '2 ', $str1);            Return $getstr1;        } elseif (isset($_SERVER['HTTP_X_UP_CALLING_LINE_ID '])) {            $getstr2 = $_SERVER['HTTP_X_UP_CALLING_LINE_ID '];            Return $getstr2;        } elseif (isset($_SERVER['HTTP_X_UP_SUBNO '])) {            $str3 = $_SERVER['HTTP_X_UP_SUBNO '];            $getstr3 = preg_replace('/(.*)(11[d])(.*)/i ', '2 ', $str3);            Return $getstr3;        } elseif (isset($_SERVER['DEVICEID '])) {            Return $_SERVER['DEVICEID '];        } else {            Return false;        }    }    /**     *   函數名稱:   getHttpHeader     *   函數功能:   取頭資訊     *   輸入參數:   none     *   函數傳回值:   成功返回號碼,失敗返回false     *   其它說明:   說明     */    function getHttpHeader()    {        $str = ' ';        foreach ($_SERVER as $key => $val) {            $gstr = str_replace("& ", "& ", $val);            $str .= "$key   ->   " . $gstr . "rn ";        }        Return $str;    }    /**     *   函數名稱:   getUA     *   函數功能:   取UA     *   輸入參數:   none     *   函數傳回值:   成功返回號碼,失敗返回false     *   其它說明:   說明     */    function getUA()    {        if (isset($_SERVER['HTTP_USER_AGENT '])) {            Return $_SERVER['HTTP_USER_AGENT '];        } else {            Return false;        }    }    /**     *   函數名稱:   getPhoneType     *   函數功能:   取得手機類型     *   輸入參數:   none     *   函數傳回值:   成功返回string,失敗返回false     *   其它說明:   說明     */    function getPhoneType()    {        $ua = $this->getUA();        if ($ua != false) {            $str = explode('   ', $ua);            Return $str[0];        } else {            Return false;        }    }    /**     *   函數名稱:   isOpera     *   函數功能:   判斷是否是opera     *   輸入參數:   none     *   函數傳回值:   成功返回string,失敗返回false     *   其它說明:   說明     */    function isOpera()    {        $uainfo = $this->getUA();        if (preg_match('/.*Opera.*/i ', $uainfo)) {            Return true;        } else {            Return false;        }    }    /**     *   函數名稱:   isM3gate     *   函數功能:   判斷是否是m3gate     *   輸入參數:   none     *   函數傳回值:   成功返回string,失敗返回false     *   其它說明:   說明     */    function isM3gate()    {        $uainfo = $this->getUA();        if (preg_match('/M3Gate/i ', $uainfo)) {            Return true;        } else {            Return false;        }    }    /**     *   函數名稱:   getHttpAccept     *   函數功能:   取得HA     *   輸入參數:   none     *   函數傳回值:   成功返回string,失敗返回false     *   其它說明:   說明     */    function getHttpAccept()    {        if (isset($_SERVER['HTTP_ACCEPT '])) {            Return $_SERVER['HTTP_ACCEPT '];        } else {            Return false;        }    }    /**     *   函數名稱:   getIP     *   函數功能:   取得手機IP     *   輸入參數:   none     *   函數傳回值:   成功返回string     *   其它說明:   說明     */    function getIP()    {        $ip = getenv('REMOTE_ADDR ');        $ip_ = getenv('HTTP_X_FORWARDED_FOR ');        if (($ip_ != " ") && ($ip_ != "unknown ")) {            $ip = $ip_;        }        return $ip;    }}?>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.