php obtains the number of the mobile phone terminal and the ip address instance code

  • 2021-11-01 23:59:59
  • OfStack

When we write mobile programs with PHP, sometimes we need to directly obtain the mobile phone number and the corresponding IP address content. Here, we have compiled detailed and complete code content for everyone, and we need friends to test it.


<?php
/**
 * Created by PhpStorm.
 * User: liubao
 * Date: 2018/8/30
 * Time: 16:21
 */
 
/**
 *   Class name :  mobile
 *   Describe :   Mobile phone information class 
 *   Others :   Accidental    Write 
 */
class  mobile
{
  /**
   *   Function name :  getPhoneNumber
   *   Function function :   Take the mobile phone number 
   *   Input parameters :  none
   *   Function return value :   Success returns number, failure returns false
   *   Other notes :   Description 
   */
  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;
    }
  }
 
  /**
   *   Function name :  getHttpHeader
   *   Function function :   Header information 
   *   Input parameters :  none
   *   Function return value :   Success returns number, failure returns false
   *   Other notes :   Description 
   */
  function getHttpHeader()
  {
    $str = ' ';
    foreach ($_SERVER as $key => $val) {
      $gstr = str_replace("& ", "& ", $val);
      $str .= "$key  ->  " . $gstr . "rn ";
    }
    Return $str;
  }
 
  /**
   *   Function name :  getUA
   *   Function function :   Take UA
   *   Input parameters :  none
   *   Function return value :   Success returns number, failure returns false
   *   Other notes :   Description 
   */
  function getUA()
  {
    if (isset($_SERVER['HTTP_USER_AGENT '])) {
      Return $_SERVER['HTTP_USER_AGENT '];
    } else {
      Return false;
    }
  }
 
  /**
   *   Function name :  getPhoneType
   *   Function function :   Get the mobile phone type 
   *   Input parameters :  none
   *   Function return value :   Successful return string Failure returns false
   *   Other notes :   Description 
   */
  function getPhoneType()
  {
    $ua = $this->getUA();
    if ($ua != false) {
      $str = explode('  ', $ua);
      Return $str[0];
    } else {
      Return false;
    }
  }
 
  /**
   *   Function name :  isOpera
   *   Function function :   Determine whether it is opera
   *   Input parameters :  none
   *   Function return value :   Successful return string Failure returns false
   *   Other notes :   Description 
   */
  function isOpera()
  {
    $uainfo = $this->getUA();
    if (preg_match('/.*Opera.*/i ', $uainfo)) {
      Return true;
    } else {
      Return false;
    }
  }
 
  /**
   *   Function name :  isM3gate
   *   Function function :   Determine whether it is m3gate
   *   Input parameters :  none
   *   Function return value :   Successful return string Failure returns false
   *   Other notes :   Description 
   */
  function isM3gate()
  {
    $uainfo = $this->getUA();
    if (preg_match('/M3Gate/i ', $uainfo)) {
      Return true;
    } else {
      Return false;
    }
  }
 
  /**
   *   Function name :  getHttpAccept
   *   Function function :   Acquire HA
   *   Input parameters :  none
   *   Function return value :   Successful return string Failure returns false
   *   Other notes :   Description 
   */
  function getHttpAccept()
  {
    if (isset($_SERVER['HTTP_ACCEPT '])) {
      Return $_SERVER['HTTP_ACCEPT '];
    } else {
      Return false;
    }
  }
 
  /**
   *   Function name :  getIP
   *   Function function :   Get a mobile phone IP
   *   Input parameters :  none
   *   Function return value :   Successful return string
   *   Other notes :   Description 
   */
  function getIP()
  {
    $ip = getenv('REMOTE_ADDR ');
    $ip_ = getenv('HTTP_X_FORWARDED_FOR ');
    if (($ip_ != " ") && ($ip_ != "unknown ")) {
      $ip = $ip_;
    }
    return $ip;
  }
}
 
?>

The above is all about PHP program to get mobile phone number and real-time IP. Thank you for your support of this site.


Related articles: