Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. <?php
  2. function usersOnline () {
  3. $timestamp = time();
  4. $ip = ipCheck();
  5. }
  6.  
  7. function ipCheck() {
  8. if (getenv('HTTP_CLIENT_IP')) {
  9. $ip = getenv('HTTP_CLIENT_IP');
  10. }
  11. elseif (getenv('HTTP_X_FORWARDED_FOR')) {
  12. $ip = getenv('HTTP_X_FORWARDED_FOR');
  13. }
  14. elseif (getenv('HTTP_X_FORWARDED')) {
  15. $ip = getenv('HTTP_X_FORWARDED');
  16. }
  17. elseif (getenv('HTTP_FORWARDED_FOR')) {
  18. $ip = getenv('HTTP_FORWARDED_FOR');
  19. }
  20. elseif (getenv('HTTP_FORWARDED')) {
  21. $ip = getenv('HTTP_FORWARDED');
  22. }
  23. else {
  24. $ip = $_SERVER['REMOTE_ADDR'];
  25. }
  26. return $ip;
  27. }
  28.  
  29. function new_user_online() {
  30. $db = DB::getInstance();
  31. $ip = ipCheck();
  32. $timestamp = time();
  33. $checkFirst = $db->query("SELECT * FROM users_online WHERE ip = ?",array($ip));
  34. $count = $checkFirst->count();
  35.  
  36. if($count == 0){
  37. $fields =array('timestamp'=>$timestamp, 'ip'=>$ip);
  38. $db->insert('users_online',$fields);
  39. }else{
  40. $fields =array('timestamp'=>$timestamp);
  41. $checkQ = $db->query("SELECT id FROM users_online WHERE ip = ?",array($ip));
  42. $to_update = $checkQ->first();
  43. $db->update('users_online',$to_update->id,$fields);
  44. }
  45. }
  46.  
  47. function delete_user_online() {
  48. $db = DB::getInstance();
  49. $timeout = 900;
  50. $timestamp = time();
  51. $delete = $db->query("DELETE FROM useronline WHERE timestamp < ($timestamp - $timeout)");
  52. }
  53.  
  54. function count_users() {
  55. $db = DB::getInstance();
  56. $selectAll = $db->query("SELECT DISTINCT ip FROM useronline");
  57. $count = $selectAll->count();
  58. return $count;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement