strago Posted September 13, 2010 Share Posted September 13, 2010 How do you have a log generate two different logs, and having where it posts the log at, depend on if it's a visitor, or a search engine spider HTTP_USER_AGENT (Like Googlebot, Msnbot, Yahoo! Slurp.) <?php define("DATE_FORMAT","m-d-Y - H:i:s"); define("LOG_FILE","/full_path/visitors.html"); define("LOG_FILE2","/full_path/search_engine_bots.html"); $logfileHeader='DATE - IP - HOSTNAME - BROWSER - URI - REFERRER'."\n"; $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) && ($_SERVER['HTTP_USER_AGENT'] != "")) ? $_SERVER['HTTP_USER_AGENT'] : "Unknown"; $userIp = (isset($_SERVER['REMOTE_ADDR']) && ($_SERVER['REMOTE_ADDR'] != "")) ? $_SERVER['REMOTE_ADDR'] : "Unknown"; $refferer = (isset($_SERVER['HTTP_REFERER']) && ($_SERVER['HTTP_REFERER'] != "")) ? $_SERVER['HTTP_REFERER'] : "Unknown"; $uri = (isset($_SERVER['REQUEST_URI']) && ($_SERVER['REQUEST_URI'] != "")) ? $_SERVER['REQUEST_URI'] : "Unknown"; $hostName = gethostbyaddr($userIp); $actualTime = date(DATE_FORMAT); $logEntry = "$actualTime - $userIp - $hostName - $userAgent - $uri - $refferer<BR>\n"; if (!file_exists(LOG_FILE)) { $logFile = fopen(LOG_FILE,"w"); fwrite($logFile, $logfileHeader); } else { $logFile = fopen(LOG_FILE,"a"); } fwrite($logFile,$logEntry); fclose($logFile); ?> Link to comment https://forums.phpfreaks.com/topic/213304-two-logs-one-loging-visitors-and-another-one-loging-search-engines/ Share on other sites More sharing options...
schilly Posted September 13, 2010 Share Posted September 13, 2010 Ya just check the user agent for known crawlers. You should be able to find a list somewhere. http://www.user-agents.org/ Link to comment https://forums.phpfreaks.com/topic/213304-two-logs-one-loging-visitors-and-another-one-loging-search-engines/#findComment-1110617 Share on other sites More sharing options...
strago Posted September 13, 2010 Author Share Posted September 13, 2010 For a search engine only log, would I only need to change ($_SERVER['HTTP_USER_AGENT'] != "")) to ($_SERVER['HTTP_USER_AGENT'] != "Googlebot|MantraAgent|Slurp|WebCrawler|ia_archiver|FAST-WebCrawler")) and add an else for making a log that doesn't contain those? Link to comment https://forums.phpfreaks.com/topic/213304-two-logs-one-loging-visitors-and-another-one-loging-search-engines/#findComment-1110761 Share on other sites More sharing options...
schilly Posted September 13, 2010 Share Posted September 13, 2010 Ya that should work. Does using an OR in a string work? Never tried that before. Link to comment https://forums.phpfreaks.com/topic/213304-two-logs-one-loging-visitors-and-another-one-loging-search-engines/#findComment-1110767 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.