Guest User

Untitled

a guest
Mar 22nd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. <?php
  2. // Menyisipkan file Koneksi ke database
  3. // File ini diperlukan saat berinteraksi dengan database Seperti INSERT, UPDATE, DELETE dan SELECT
  4. require 'config.php';
  5.  
  6. // Menyisipkan file functions.php agar function yang kita buat dapat dipakai dihalaman ini
  7. require 'functions.php';
  8.  
  9. /**
  10. * Test
  11. * echo ip_user();
  12. * echo "<br/>";
  13. * echo browser_user();
  14. * echo "<br/>";
  15. * echo os_user();
  16. */
  17.  
  18. // rekam data user yang sudah mengakses website kita
  19. $ip = ip_user();
  20. $browser = browser_user();
  21. $os = os_user();
  22.  
  23. // untuk tes hilangkan comment dibawah ini
  24. // unset($_COOKIE['VISITOR']);
  25.  
  26. // Check bila sebelumnya data pengunjung sudah terrekam
  27. if (! isset($_COOKIE['VISITOR'])) {
  28.  
  29. // Masa akan direkam kembali
  30. // Tujuan untuk menghindari merekam pengunjung yang sama dihari yang sama.
  31. // Cookie akan disimpan selama 24 jam
  32. $duration = time()+60*60*24;
  33.  
  34. // simpan kedalam cookie browser
  35. setcookie('VISITOR',$browser,$duration);
  36.  
  37. // current time
  38. $dateTime = date('Y-m-d H:i:s');
  39.  
  40. // SQL Command atau perintah SQL INSERT
  41. $sql = "INSERT INTO statistik (ip, os, browser, date_create) VALUES ('$ip', '$os', '$browser', '$dateTime')";
  42.  
  43. // variabel { $db } adalah perwakilan dari koneksi database lihat config.php
  44. $query = $db->query($sql);
  45. }
  46.  
  47. echo "<p>Untuk Melihat Siapa saja yang akses silahkan buka <a href=\"admin.php\"/>Admin.php</a></p>";
Add Comment
Please, Sign In to add comment