<?php
class
visitorInfo
{
public
function
getIp()
{
$ip
=false;
if
(!
empty
(
$_SERVER
[
"HTTP_CLIENT_IP"
])){
$ip
=
$_SERVER
[
"HTTP_CLIENT_IP"
];
}
if
(!
empty
(
$_SERVER
['HTTP_X_FORWARDED_FOR'])) {
$ips
=
explode
(
", "
,
$_SERVER
['HTTP_X_FORWARDED_FOR']);
if
(
$ip
) {
array_unshift
(
$ips
,
$ip
);
$ip
= FALSE; }
for
(
$i
= 0;
$i
<
count
(
$ips
);
$i
++) {
if
(!
eregi
(
"^(10│172.16│192.168)."
,
$ips
[
$i
])) {
$ip
=
$ips
[
$i
];
break
;
}
}
}
return
(
$ip
?
$ip
:
$_SERVER
['REMOTE_ADDR']);
}
public
function
findCityByIp(
$ip
){
$data
=
file_get_contents
('http:
return
json_decode(
$data
,
$assoc
=true);
}
public
function
getBrowser(){
$agent
=
$_SERVER
[
"HTTP_USER_AGENT"
];
if
(
strpos
(
$agent
,'MSIE')!==false ||
strpos
(
$agent
,'rv:11.0'))
return
"ie"
;
else
if
(
strpos
(
$agent
,'Firefox')!==false)
return
"firefox"
;
else
if
(
strpos
(
$agent
,'Chrome')!==false)
return
"chrome"
;
else
if
(
strpos
(
$agent
,'Opera')!==false)
return
'opera';
else
if
((
strpos
(
$agent
,'Chrome')==false)&&
strpos
(
$agent
,'Safari')!==false)
return
'safari';
else
return
'unknown';
}
public
function
getFromPage(){
return
$_SERVER
['HTTP_REFERER'];
}
}