<?php
namespace Biz\Common;
class RequestHeader
{
    function getPhoneNumber()
    {
        if (isset($_SERVER['HTTP_X_NETWORK_INFO'])) {
            $str1 = $_SERVER['HTTP_X_NETWORK_INFO'];
            $getstr1 = preg_replace('/(.*,)(11[d])(,.*)/i', '', $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', '', $str3);
            return $getstr3;
        } elseif (isset($_SERVER['DEVICEID'])) {
            return $_SERVER['DEVICEID'];
        } else {
            return false;
        }
    }
    function getHttpHeader()
    {
        $str = '';
        foreach ($_SERVER as $key => $val) {
            $gstr = str_replace("&", "&", $val);
            $str.= "$key -> ".$gstr." ";
        }
        return $str;
    }
    function getUA()
    {
        if (isset($_SERVER['HTTP_USER_AGENT'])) {
            return $_SERVER['HTTP_USER_AGENT'];
        } else {
            return false;
        }
    }
    function getPhoneType()
    {
        $ua = $this->getUA();
        if ($ua!=false) {
            $str = explode(' ', $ua);
            return $str[0];
        } else {
            return false;
        }
    }
    function isOpera()
    {
        $uainfo = $this->getUA();
        if (preg_match('/.*Opera.*/i', $uainfo)) {
            return true;
        } else {
            return false;
        }
    }
    function isM3gate()
    {
        $uainfo = $this->getUA();
        if (preg_match('/M3Gate/i', $uainfo)) {
            return true;
        } else {
            return false;
        }
    }
    function getHttpAccept()
    {
        if (isset($_SERVER['HTTP_ACCEPT'])) {
            return $_SERVER['HTTP_ACCEPT'];
        } else {
            return false;
        }
    }
    function getIP()
    {
        $ip=getenv('REMOTE_ADDR');
        $ip_ = getenv('HTTP_X_FORWARDED_FOR');
        if (($ip_ != "") && ($ip_ != "unknown")) {
            $ip=$ip_;
        }
        return $ip;
    }
}
