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 = ''; } preg_match ( "/[\d\.]{7,15}/", $cip, $cips ); $cip = isset ( $cips [0] ) ? $cips [0] : 'unknown'; 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!