|
|
|
สอบถามโค้ด PHP ดึงค่า IP Address ของเครื่อง Client |
|
|
|
|
|
|
|
มันไม่มีแบบที่ผมต้องการ ตามด้านบนมันแค่ดึงไอพีเครื่องเว็บเซอเวอร์ครับ
|
|
|
|
|
Date :
2014-03-01 15:05:11 |
By :
akespeed |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$_SERVER['SERVER_ADDR']
Client
|
|
|
|
|
Date :
2014-03-01 16:21:48 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
function get_client_ip() {
$ipaddress = '';
if ($_SERVER['HTTP_CLIENT_IP'])
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['HTTP_X_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_X_FORWARDED'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if($_SERVER['HTTP_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if($_SERVER['HTTP_FORWARDED'])
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if($_SERVER['REMOTE_ADDR'])
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
ลองดูครับ
|
|
|
|
|
Date :
2014-03-01 16:29:46 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เพิ่มอันนี้เข้าไปอีกตัว คุณวิน
HTTP_X_CLUSTER_CLIENT_IP
เอามาจาก fuelphp
Code (PHP)
public static function real_ip($default = '0.0.0.0', $exclude_reserved = false)
{
static $server_keys = null;
if (empty($server_keys))
{
$server_keys = array('HTTP_CLIENT_IP', 'REMOTE_ADDR');
if (\Config::get('security.allow_x_headers', false))
{
$server_keys = array_merge(array('HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_X_FORWARDED_FOR'), $server_keys);
}
}
foreach ($server_keys as $key)
{
if ( ! static::server($key))
{
continue;
}
$ips = explode(',', static::server($key));
array_walk($ips, function (&$ip) {
$ip = trim($ip);
});
$ips = array_filter($ips, function($ip) use($exclude_reserved) {
return filter_var($ip, FILTER_VALIDATE_IP, $exclude_reserved ? FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE : null);
});
if ($ips)
{
return reset($ips);
}
}
return \Fuel::value($default);
}
|
|
|
|
|
Date :
2014-03-02 01:50:56 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จัดไปครับ
|
|
|
|
|
Date :
2014-03-02 09:31:59 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|