Advertisement
ujiajah1

counter_visitor.php

May 13th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php
  2. include "connect.php";
  3.  
  4. // Detect Browser
  5. $browser = $_SERVER['HTTP_USER_AGENT'];
  6. $chrome = '/Chrome/';
  7. $firefox = '/Firefox/';
  8. $ie = '/MSIE/';
  9. if (preg_match($chrome, $browser))
  10.     $data = "Chrome/Opera";
  11. if (preg_match($firefox, $browser))
  12.     $data = "Firefox";
  13. if (preg_match($ie, $browser))
  14.     $data = "IE";
  15.  
  16. // Ambil Informasi Yang diperlukan dari Pengunjung
  17. $ipaddress = $_SERVER['REMOTE_ADDR']."";
  18. $browser = $data;
  19. $tanggal = date('Y-m-d');
  20. $kunjungan = 1;
  21. // Daftarkan Kedalam Session Lalu Simpan Ke Database
  22. if (!isset($_SESSION['visitor'])){
  23. $_SESSION['visitor']=$ipaddress;
  24. mysql_query("INSERT INTO visitor (tanggal,ip_address,counter,browser) VALUES ('".$tanggal."','".$ipaddress."','".$kunjungan."','".$browser."')");
  25. }
  26. // Hitung Jumlah Visitor
  27. $kemarin    = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-1,date('Y')));
  28. $hari_ini   = mysql_fetch_array(mysql_query('SELECT sum(counter) AS hari_ini FROM visitor WHERE tanggal="'.date("Y-m-d").'"'));
  29. $kemarin    = mysql_fetch_array(mysql_query('SELECT sum(counter) AS kemarin FROM visitor WHERE tanggal="'.$kemarin.'"'));
  30. $sql = mysql_fetch_array(mysql_query('SELECT sum(counter) as total FROM visitor'));
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement