代码如下:
class CookieTool{
......
......
......
protected function getIPAddress(): string{
$ipaddress = "";
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
protected function getBrowser($agent): string{
$browserAgent = "";
if(strstr($agent, 'MSIE')) {
$browserAgent="Internet Explorer";
}
else if(strstr($agent, 'Opera')) {
$browserAgent="Opera";
}
else if(strstr($agent, 'Firefox')) {
$browserAgent="Firefox";
}
else if(strstr($agent, 'Chrome')) {
$browserAgent = "Chrome";
}
else if(strstr($agent, 'Safari')) {
$browserAgent = "Safari";
}
else{
$browserAgent = "unknown";
}
return $browserAgent;
}
protected function getPlatform($agent): string{
$agent = strtolower($agent);
$platform = "";
if(strstr($agent, 'win')) {
$platform="windows";
}
else if(strstr($agent, 'linux')) {
$platform = "linux";
}
else{
$platform = "unknown";
}
return $platform;
}
protected function getMacAddress(): string{
$MAC = exec('getmac');
print_r($MAC);
$MAC = strtok($MAC, ' ');
return $MAC;
}
public function printCookieArray(){
global $cookieAndSessionArray;
print_r($cookieAndSessionArray);
}
public function XXXXXX(){
$ipAddress = $this->getIPAddress();
$browserAgent = $this->getBrowser($_SERVER['HTTP_USER_AGENT']);
$platform = $this->getPlatform($_SERVER['HTTP_USER_AGENT']);
echo $ipAddress . "<br/>";
echo $browserAgent . "<br/>";
echo $platform . "<br/>";
}
}
运行截图如下:
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://it1995.blog.csdn.net/article/details/123321997
内容来源于网络,如有侵权,请联系作者删除!