Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- class user_system
- {
- var $status;
- var $user_info;
- var $errors;
- var $db;
- function user_system()
- {
- $this->db = $GLOBALS['db'];
- if ($_SESSION['DH_US'] || $_POST['DH_US_username'])
- {
- if ($_SESSION['DH_US']['username'] && $_SESSION['DH_US']['password'])
- {
- $this->user_info = array(
- 'username' => $_SESSION['DH_US']['username'],
- 'password' => $_SESSION['DH_US']['password']
- );
- }
- elseif ($_POST['DH_US_login'])
- {
- $this->user_info = array(
- 'username' => $_POST['DH_US_username'],
- 'password' => md5($_POST['DH_US_password'])
- );
- }
- }
- $this->set_online();
- }
- function check_login()
- {
- if (!empty($this->user_info['username']) && !empty($this->user_info['password']))
- {
- $user = $this->db->Execute("SELECT * FROM `" . $this->db->db_info['tables']['users'] . "` WHERE `username`='" . $this->user_info['username'] . "'")->FetchRow();
- if ($user['password'] == $this->user_info['password'])
- {
- $_SESSION['DH_US'] = array(
- 'id' => $user['id'],
- 'username' => $user['username'],
- 'password' => $user['password']
- );
- $this->user_info = $_SESSION['DH_US'];
- $this->user_info['level'] = $user['level'];
- $this->status = 'logged_in';
- return true;
- }
- else
- {
- session_destroy();
- $this_status = 'guest';
- $this->errors[] = "Empty Username or Password.";
- return false;
- }
- }
- else
- {
- session_destory();
- $this->status = 'guest';
- $this->errors[] = "Invalid Username or Password.";
- return false;
- }
- }
- function register()
- {
- $username = $GLOBALS['getvar']->get('DH_US_username', 'POST', 'STRING');
- $password = md5($_POST['DH_US_password']);
- $email = $GLOBALS['getvar']->get('DH_US_email', 'POST', 'EMAIL');
- $ip = $GLOBALS['getvar']->get('REMOTE_ADDR', 'SERVER');
- $browser = $GLOBALS['getvar']->get('HTTP_USER_AGENT', 'SERVER');
- if (empty($username))
- {
- $this->errors[] = "Registration Error: Invalid Username.";
- }
- if (empty($_POST['DH_US_password']))
- {
- $this->errors[] = "Registration Error: Invalid Password.";
- }
- if (empty($email))
- {
- $this->errors[] = "Registration Error: Invalid Email.";
- }
- if ($this->db->Execute("SELECT * FROM `" . $this->db->db_info['tables']['users'] . "` WHERE `username`='" . $username . "'")->RecordCount() > 0)
- {
- $this->errors[] = "Registration Error: Username Exists";
- }
- if (!$this->errors)
- {
- $this->db->Execute("INSERT INTO `" . $this->db->db_info['tables']['users'] . "` (`username`, `password`, `email`) VALUES ('" . $username . "', '" . $password . "', '" . $email . "')");
- }
- }
- function set_online()
- {
- $ip = $GLOBALS['getvar']->get('REMOTE_ADDR', 'SERVER', 'string');
- $browser = $GLOBALS['getvar']->get('HTTP_USER_AGENT', 'SERVER', 'string');
- $host = gethostbyaddr(gethostbyname($ip));
- foreach ($GLOBALS['url'] AS $path)
- {
- if (!empty($path))
- {
- $viewing .= "/" . $path;
- }
- }
- if ($this->status == 'logged_in')
- {
- if ($this->db->Execute("SELECT * FROM `" . $this->db->db_info['tables']['users_online'] . "` WHERE `user_id`='" . $this->user_info['id'] . "'")->RecordCount() > 0)
- {
- $this->db->Execute("UPDATE `" . $this->db->db_info['tables']['users_online'] . "` SET `time`='" . time() . "', `viewing`='" . $viewing . "' WHERE `user_id`='" . $this->user_info['id'] . "'");
- }
- else
- {
- $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 . "')");
- }
- }
- else
- {
- if ($this->db->Execute("SELECT * FROM `" . $this->db->db_info['tables']['users_online'] . "` WHERE `user_ip`='" . $ip . "' AND `user_id`='0'")->RecordCount() > 0)
- {
- if ($ip == '68.56.85.212')
- {
- echo "UPDATE `" . $this->db->db_info['tables']['users_online'] . "` SET `time`='" . time() . "', `viewing`='" . $viewing . "', WHERE `user_id`='0' AND `user_ip`='" . $ip . "'";
- }
- $this->db->Execute("UPDATE `" . $this->db->db_info['tables']['users_online'] . "` SET `time`='" . time() . "', `viewing`='" . $viewing . "' WHERE `user_id`='0' AND `user_ip`='" . $ip . "'");
- }
- else
- {
- echo 'insert guest';
- $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 . "')");
- }
- }
- }
- function output_errors()
- {
- foreach ($this->errors AS $error)
- {
- echo $error . "<br />";
- }
- }
- }
- $DH_US = new user_system;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement