Home  >  Article  >  Backend Development  >  PHP method for server-side predefined variable $_SERVER

PHP method for server-side predefined variable $_SERVER

墨辰丷
墨辰丷Original
2018-06-09 14:54:441648browse

This article mainly introduces PHP's method for server-side predefined variables $_SERVER. Interested friends can refer to it. I hope it will be helpful to everyone.

The example of this article describes how PHP determines the access IP, as follows:

<?php 
function getIP() { 
  if (! empty ( $_SERVER ["HTTP_CLIENT_IP"] )) { 
    $cip = $_SERVER ["HTTP_CLIENT_IP"]; 
  } else if (! empty ( $_SERVER ["HTTP_X_FORWARDED_FOR"] )) { 
    $cip = $_SERVER ["HTTP_X_FORWARDED_FOR"]; 
  } else if (! empty ( $_SERVER ["REMOTE_ADDR"] )) { 
    $cip = $_SERVER ["REMOTE_ADDR"]; 
  } else { 
    $cip = &#39;&#39;; 
  } 
  preg_match ( "/[\d\.]{7,15}/", $cip, $cips ); 
  $cip = isset ( $cips [0] ) ? $cips [0] : &#39;unknown&#39;; 
  unset ( $cips ); 
  return $cip; 
} 
?>

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

Related recommendations:

php recursive traversal to achieve infinite classification

php to implement a news release system

php function to query songs through the Sina music library search interface

The above is the detailed content of PHP method for server-side predefined variable $_SERVER. 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