|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Funcs about client side info |
|
4
|
|
|
* |
|
5
|
|
|
* @package fwolflib |
|
6
|
|
|
* @subpackage func |
|
7
|
|
|
* @copyright Copyright 2003-2009, Fwolf |
|
8
|
|
|
* @author Fwolf <[email protected]> |
|
9
|
|
|
* @since 2006-07-03 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
require_once(dirname(__FILE__) . '/../fwolflib.php'); |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Convert user ip from hex string |
|
18
|
|
|
* |
|
19
|
|
|
* @deprecated Use Fwlib\Util\Ip::fromHex() |
|
20
|
|
|
* @param string $hex |
|
21
|
|
|
* @return string |
|
22
|
|
|
* @link http://us.php.net/uniqid |
|
23
|
|
|
*/ |
|
24
|
|
View Code Duplication |
function ClientIpFromHex($hex) { |
|
25
|
|
|
$ip = ""; |
|
26
|
|
|
if (8 == strlen($hex)) { |
|
27
|
|
|
$ip .= hexdec(substr($hex ,0 ,2)) . '.'; |
|
28
|
|
|
$ip .= hexdec(substr($hex ,2 ,2)) . '.'; |
|
29
|
|
|
$ip .= hexdec(substr($hex ,4 ,2)) . '.'; |
|
30
|
|
|
$ip .= hexdec(substr($hex ,6 ,2)); |
|
31
|
|
|
} |
|
32
|
|
|
return $ip; |
|
33
|
|
|
} // end of func ClientIpFromHex |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Convert user ip to hex string |
|
38
|
|
|
* |
|
39
|
|
|
* @deprecated Use Fwlib\Util\Ip::toHex() |
|
40
|
|
|
* @param string $ip |
|
41
|
|
|
* @return string |
|
42
|
|
|
* @link http://us.php.net/uniqid |
|
43
|
|
|
*/ |
|
44
|
|
|
function ClientIpToHex($ip = "") { |
|
45
|
|
|
$hex = ""; |
|
46
|
|
|
if('' == $ip) |
|
47
|
|
|
//$ip = getenv('REMOTE_ADDR'); |
|
48
|
|
|
$ip = GetClientIp(); |
|
49
|
|
View Code Duplication |
if (false == ip2long($ip)) |
|
|
|
|
|
|
50
|
|
|
return ''; |
|
51
|
|
|
else { |
|
52
|
|
|
$part = explode('.', $ip); |
|
53
|
|
|
if (4 != count($part)) |
|
54
|
|
|
return ''; |
|
55
|
|
|
else |
|
56
|
|
|
for ($i=0; $i<=count($part)-1; $i++) { |
|
57
|
|
|
$hex .= substr('0' . dechex($part[$i]), -2); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
return $hex; |
|
61
|
|
|
} // end of func ClientIpToHex |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* 检查客户端的浏览器是NS还是IE |
|
66
|
|
|
* |
|
67
|
|
|
* @deprecated Use Fwlib\Util\HttpUtil::getBrowserType() |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
function GetBrowserType() |
|
71
|
|
|
{ |
|
72
|
|
|
$str = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
|
73
|
|
|
if (false === strpos($str, 'MSIE')) { |
|
74
|
|
|
return('NS'); |
|
75
|
|
|
} |
|
76
|
|
|
else { |
|
77
|
|
|
return('IE'); |
|
78
|
|
|
} |
|
79
|
|
|
} // end func GetBrowserType |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get ip of client |
|
84
|
|
|
* |
|
85
|
|
|
* @deprecated Use Fwlib\Util\HttpUtil::getClientIp() |
|
86
|
|
|
* @return string |
|
87
|
|
|
* @link http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html |
|
88
|
|
|
*/ |
|
89
|
|
|
function GetClientIp() { |
|
90
|
|
|
$s = ''; |
|
91
|
|
|
|
|
92
|
|
|
// Original way: check ip from share internet |
|
93
|
|
|
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
94
|
|
|
$s = $_SERVER['HTTP_CLIENT_IP']; |
|
95
|
|
|
} |
|
96
|
|
|
// Using proxy ? |
|
97
|
|
|
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
98
|
|
|
$s = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
99
|
|
|
} |
|
100
|
|
|
// Another way |
|
101
|
|
|
elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
|
102
|
|
|
$s = $_SERVER['REMOTE_ADDR']; |
|
103
|
|
|
} |
|
104
|
|
|
else { |
|
105
|
|
|
$s = ''; |
|
106
|
|
|
} |
|
107
|
|
|
return $s; |
|
108
|
|
|
} // end of func GetClientIp |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
?> |
|
112
|
|
|
|