3月 6th, 2009

获取客户端IP的PHP函数

Category: 程序开发, 网络应用, php, Author: admin, Popularity: 29%

<?php
function get_ip_address() {
if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
} else {
if (getenv(‘HTTP_X_FORWARDED_FOR’)) {
$ip = getenv(‘HTTP_X_FORWARDED_FOR’);
} elseif (getenv(‘HTTP_CLIENT_IP’)) {
$ip = getenv(‘HTTP_CLIENT_IP’);
} else {
$ip = getenv(‘REMOTE_ADDR’);
}
}
return $ip;
}
echo get_ip_address();
?>

相关日志

Tags:, .
评论数量() | Add Comments
本文网址:http://www.9usb.net/200903/php-get-ip-address.html

There are No comments.

» You can leave a response

leave a reply