Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.99 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.     class user_system
  4.     {
  5.         var $status;
  6.         var $user_info;
  7.         var $errors;
  8.         var $db;
  9.         function user_system()
  10.         {
  11.             $this->db = $GLOBALS['db'];
  12.             if ($_SESSION['DH_US'] || $_POST['DH_US_username'])
  13.             {
  14.                 if ($_SESSION['DH_US']['username'] && $_SESSION['DH_US']['password'])
  15.                 {
  16.                     $this->user_info = array(
  17.                         'username' => $_SESSION['DH_US']['username'],
  18.                         'password' => $_SESSION['DH_US']['password']
  19.                     );
  20.                 }
  21.                 elseif ($_POST['DH_US_login'])
  22.                 {
  23.                     $this->user_info = array(
  24.                         'username' => $_POST['DH_US_username'],
  25.                         'password' => md5($_POST['DH_US_password'])
  26.                     );
  27.                 }
  28.             }
  29.             $this->set_online();
  30.         }
  31.  
  32.         function check_login()
  33.         {
  34.             if (!empty($this->user_info['username']) && !empty($this->user_info['password']))
  35.             {
  36.                 $user = $this->db->Execute("SELECT * FROM `" . $this->db->db_info['tables']['users'] . "` WHERE `username`='" . $this->user_info['username'] . "'")->FetchRow();
  37.                 if ($user['password'] == $this->user_info['password'])
  38.                 {
  39.                     $_SESSION['DH_US'] = array(
  40.                         'id' => $user['id'],
  41.                         'username' => $user['username'],
  42.                         'password' => $user['password']
  43.                     );
  44.                     $this->user_info = $_SESSION['DH_US'];
  45.                     $this->user_info['level'] = $user['level'];
  46.                     $this->status = 'logged_in';
  47.                     return true;
  48.                 }
  49.                 else
  50.                 {
  51.                     session_destroy();
  52.                     $this_status = 'guest';
  53.                     $this->errors[] = "Empty Username or Password.";
  54.                     return false;
  55.                 }
  56.             }
  57.             else
  58.             {
  59.                 session_destory();
  60.                 $this->status = 'guest';
  61.                 $this->errors[] = "Invalid Username or Password.";
  62.                 return false;
  63.             }
  64.         }
  65.         function register()
  66.         {
  67.             $username = $GLOBALS['getvar']->get('DH_US_username', 'POST', 'STRING');
  68.             $password = md5($_POST['DH_US_password']);
  69.             $email = $GLOBALS['getvar']->get('DH_US_email', 'POST', 'EMAIL');
  70.  
  71.             $ip = $GLOBALS['getvar']->get('REMOTE_ADDR', 'SERVER');
  72.             $browser = $GLOBALS['getvar']->get('HTTP_USER_AGENT', 'SERVER');
  73.            
  74.             if (empty($username))
  75.             {
  76.                 $this->errors[] = "Registration Error: Invalid Username.";
  77.             }
  78.             if (empty($_POST['DH_US_password']))
  79.             {
  80.                 $this->errors[] = "Registration Error: Invalid Password.";
  81.             }
  82.             if (empty($email))
  83.             {
  84.                 $this->errors[] = "Registration Error: Invalid Email.";
  85.             }
  86.             if ($this->db->Execute("SELECT * FROM `" . $this->db->db_info['tables']['users'] . "` WHERE `username`='" . $username . "'")->RecordCount() > 0)
  87.             {
  88.                 $this->errors[] = "Registration Error: Username Exists";
  89.             }
  90.             if (!$this->errors)
  91.             {
  92.                 $this->db->Execute("INSERT INTO `" . $this->db->db_info['tables']['users'] . "` (`username`, `password`, `email`) VALUES ('" . $username . "', '" . $password . "', '" . $email . "')");
  93.             }
  94.         }
  95.         function set_online()
  96.         {
  97.             $ip = $GLOBALS['getvar']->get('REMOTE_ADDR', 'SERVER', 'string');
  98.             $browser = $GLOBALS['getvar']->get('HTTP_USER_AGENT', 'SERVER', 'string');
  99.             $host = gethostbyaddr(gethostbyname($ip));
  100.  
  101.             foreach ($GLOBALS['url'] AS $path)
  102.             {
  103.                 if (!empty($path))
  104.                 {
  105.                     $viewing .= "/" . $path;
  106.                 }
  107.             }
  108.             if ($this->status == 'logged_in')
  109.             {
  110.                 if ($this->db->Execute("SELECT * FROM `" . $this->db->db_info['tables']['users_online'] . "` WHERE `user_id`='" . $this->user_info['id'] . "'")->RecordCount() > 0)
  111.                 {
  112.                     $this->db->Execute("UPDATE `" . $this->db->db_info['tables']['users_online'] . "` SET `time`='" . time() . "', `viewing`='" . $viewing . "' WHERE `user_id`='" . $this->user_info['id'] . "'");
  113.                 }
  114.                 else
  115.                 {
  116.                     $this->db->Execute("INSERT INTO `" . $this->db->db_info['tables']['users_online'] . "` (`user_id`, `user_ip`, `username`, `time`, `viewing`, `browser`, `host`) VALUES ('" . $this->user_info['id'] . "', '" . $ip . "', '" . $this->user_info['username'] . "', '" . time() . "', '" . $viewing . "', '" . $browser . "', '" . $host . "')");
  117.                 }
  118.             }
  119.             else
  120.             {
  121.                 if ($this->db->Execute("SELECT * FROM `" . $this->db->db_info['tables']['users_online'] . "` WHERE `user_ip`='" . $ip . "' AND `user_id`='0'")->RecordCount() > 0)
  122.                 {
  123. if ($ip == '68.56.85.212')
  124. {
  125. echo "UPDATE `" . $this->db->db_info['tables']['users_online'] . "` SET `time`='" . time() . "', `viewing`='" . $viewing . "',  WHERE `user_id`='0' AND `user_ip`='" . $ip . "'";
  126. }
  127.                     $this->db->Execute("UPDATE `" . $this->db->db_info['tables']['users_online'] . "` SET `time`='" . time() . "', `viewing`='" . $viewing . "'  WHERE `user_id`='0' AND `user_ip`='" . $ip . "'");
  128.                 }
  129.                 else
  130.                 {
  131. echo 'insert guest';
  132.                     $this->db->Execute("INSERT INTO `" . $this->db->db_info['tables']['users_online'] . "` (`user_id`, `user_ip`, `username`, `time`, `viewing`, `browser`, `host`) VALUES ('" . $this->user_info['id'] . "', '" . $ip . "', '" . $this->user_info['username'] . "', '" . time() . "', '" . $viewing . "', '" . $browser . "', '" . $host . "')");
  133.                 }
  134.             }
  135.         }
  136.         function output_errors()
  137.         {
  138.             foreach ($this->errors AS $error)
  139.             {
  140.                 echo $error . "<br />";
  141.             }
  142.         }
  143.     }
  144.     $DH_US = new user_system;
  145. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement