Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Implements hook_help.
- *
- * Displays help and module information.
- *
- * @param path
- * Which path of the site we're using to display help
- * @param arg
- * Array that holds the current path as returned from arg() function
- */
- function site_visitors_help($path, $arg) {
- switch ($path) {
- case "admin/help#site_visitors":
- return '<p>' . t("Displays links to nodes created on this date") . '</p>';
- break;
- }
- }
- /**
- * Implements hook_boot().
- */
- function site_visitors_boot() {
- global $start;
- $time = microtime();
- $time = explode(' ', $time);
- $time = $time[1] + $time[0];
- $start = $time;
- }
- /**
- * Implements hook_exit().
- */
- function site_visitors_exit() {
- global $user;
- if ($user->uid != 1)
- site_visitors_insert();
- }
- /**
- * Custom visitor function.
- *
- * Insert User Agent, IP Address, and URL to the database
- *
- * @return
- * A result set of the targeted posts.
- */
- function site_visitors_insert(){
- $tracker = array(
- 'database' => 'c1tracker',
- 'username' => 'c1tracker',
- 'password' => 'mypass',
- 'host' => 'localhost',
- 'driver' => 'mysql',
- );
- Database::addConnectionInfo('tracker', 'default', $tracker);
- db_set_active('tracker');
- global $start;
- //This code requires the code above to compute the start time. This will compute the total page load.
- $time = microtime();
- $time = explode(' ', $time);
- $time = $time[1] + $time[0];
- $finish = $time;
- $total_time = round(($finish - $start), 4);
- $t = $total_time;
- $url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
- $current_ip = $_SERVER['REMOTE_ADDR'];
- $user_agent = $_SERVER['HTTP_USER_AGENT'];
- function is_bot()
- {
- $botlist = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
- "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
- "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
- "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
- "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
- "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
- "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
- "Butterfly","Twitturls","Me.dium","Twiceler");
- foreach($botlist as $bot)
- {
- if(strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
- return true;
- }
- return false;
- }
- if (is_bot())
- $isbot = 1;
- else
- $isbot = 0;
- db_insert('ap_visits')
- ->fields(array(
- 'id' => NULL,
- 'length' => $t,
- 'url' => $url,
- 'current_ip' => $current_ip,
- 'user_agent' => $user_agent,
- 'date_start' => date("Y-m-d H:i:s"),
- 'is_bot' => $isbot,
- 'is_logout' => 0
- ))
- ->execute();
- db_set_active();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement