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

PHP method to obtain client IP and URL

墨辰丷
Release: 2023-03-28 07:20:01
Original
1719 people have browsed it

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;
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template