Home  >  Article  >  Backend Development  >  PHP method to obtain client IP and URL

PHP method to obtain client IP and URL

墨辰丷
墨辰丷Original
2018-05-26 11:31:181693browse

This article mainly introduces the method of obtaining the client IP and URL in PHP, and involves the related usage skills of PHP predefined server variable $_SERVER. It has certain reference value. Friends in need can refer to the following

for details As follows:

function getonlineip(){//获取用户ip
  if($_SERVER['HTTP_CLIENT_IP'])
  {
   $onlineip=$_SERVER['HTTP_CLIENT_IP']; //用户IP
  }
  else if($_SERVER['HTTP_X_FORWARDED_FOR'])
  {
   $onlineip=$_SERVER['HTTP_X_FORWARDED_FOR']; //代理IP
  }
  else
  {
   $onlineip=$_SERVER['REMOTE_ADDR']; //服务器IP
  }
  return $onlineip;
}
function curPageURL()//获取完整的url
{
  $pageURL = 'http';
  if ($_SERVER["HTTPS"] == "on")
  {
   $pageURL .= "s";
  }
  $pageURL .= "://";
  if ($_SERVER["SERVER_PORT"] != "80")
  {
   $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
  }
  else
  {
   $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
  }
  return $pageURL;
}

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

PHP implementation to obtain the real IP of the real client

Detailed interpretation of javascriptClientEvent-driven (graphic tutorial)

##angular httpclient implements HTTP ClientFunction

The above is the detailed content of PHP method to obtain client IP and URL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn