当游客访问贵网站时,这个类可以把游客的相关信息储存在数据库。 它还可以检索从它的IP地址和其它请求头的到当前页面访问者若干细节。 目前,它记录用户计算机操作系统,浏览器,IP地址,国家,城市,地理坐标,互联网服务供应商或使用ip-api.comWeb服务。 所
当游客访问贵网站时,这个类可以把游客的相关信息储存在数据库。
<?php http://www.codepearl.com include('Visitors.php'); $info=new Visitors(); $info->setSubdomain("www.codepearl.com"); $info->getVisitorInfo($_SERVER['HTTP_USER_AGENT']); $info->insertInfo(); ?> <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/html"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content="Dragan Zlatkovski"> </head> <body> </body> </html>
CREATE TABLE IF NOT EXISTS `visitors` ( `id` int(11) NOT NULL, `domain` varchar(150) NOT NULL, `ip` varchar(15) NOT NULL, `serverDate` varchar(10) NOT NULL, `serverTime` varchar(10) NOT NULL, `timeZone` varchar(100) NOT NULL, `userOS` varchar(100) NOT NULL, `userBrowser` varchar(100) NOT NULL, `userAgent` varchar(300) NOT NULL, `country` varchar(100) NOT NULL, `countryCode` varchar(10) NOT NULL, `city` varchar(100) NOT NULL, `state` varchar(10) NOT NULL, `lat` varchar(40) NOT NULL, `lon` varchar(40) NOT NULL, `isp` varchar(200) NOT NULL, `org` varchar(200) NOT NULL, `asp` varchar(200) NOT NULL ) ENGINE=MyISAM AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;
function getVisitorInfo($httpUserAgent) { $this->setUserIp(); $this->setServerDate(); $this->setServerTime(); $this->setUserOs($httpUserAgent); $this->setUserBrowser($httpUserAgent); $this->setUserAgent($httpUserAgent); $query = @unserialize(file_get_contents('http://ip-api.com/php/'.$this->getUserIp())); //获取IP接口自己可以设定 $this->setUserCountry($query['country']); $this->setUserCountryCode($query['countryCode']); $this->setUserCity($query['city']); $this->setUserStateOfRegion($query['regionName']); $this->setLatitude($query['lat']); $this->setLongitude($query['lon']); $this->setISP($query['isp']); $this->setORG($query['org']); $this->setAS($query['as']); $this->setTimeZone($query['timezone']); }