Advertisement
Guest User

Untitled

a guest
May 10th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. <?php
  2.   /* USR CLASS */  
  3. class usr {
  4.  
  5. private $connection;
  6. public function __construct($username,$password,$hash=true) {
  7.  $this->username = $username;
  8.  if($hash){
  9.  $this->password = md5($password);  
  10.  }elseif(!$hash) {
  11.       $this->password = $password;
  12.  }
  13.  
  14. }
  15.  
  16. public function db_connect() {
  17.           $this->connection = mysql_connect(USER_DB_SERVER, USER_DB_USERNAME, USER_DB_PASSWORD) or die(mysql_error());
  18. mysql_select_db(USER_DB_NAME, $this->connection) or die(mysql_error());
  19. }
  20.  
  21. public function db_disconnect() {
  22.   mysql_close( $this->connection );    
  23. }
  24.  
  25. public function _login() {
  26. $this->db_connect();
  27.    
  28.    $result = mysql_query("SELECT * FROM ".BASIC_TABLE." WHERE username='".mysql_real_escape_string($this->username)."' AND password='".mysql_real_escape_string($this->password)."'", $this->connection) or die(mysql_error());
  29.        if($this->info = mysql_fetch_assoc($result)) {//if we did return a record
  30.            return true;      // logged in    
  31.         }
  32.         else {
  33.         return false;    
  34.         }
  35.                      
  36.      $this->db_disconnect() ;
  37.        
  38. }
  39.  
  40. public function _logout() {
  41.          setcookie('login',NULL,time()-100,'/'); // destroy some cookies.
  42.         setcookie('username',NULL,time()-100,'/');    
  43.         setcookie('password',NULL,time()-100,'/');      
  44. }
  45.  
  46. public function set_cookies($expire) {
  47.         setcookie('username',$this->username,$expire,'/'); // set some cookies.  
  48.         setcookie('password',$this->password,$expire,'/');
  49.         setcookie('login',true,$expire,'/');  
  50. }
  51.  
  52.  
  53.  
  54. public function _query() {
  55.    
  56.    $this->db_connect();
  57.    
  58.    $result = mysql_query("SELECT * FROM ".PAGE_TABLE." WHERE username='".mysql_real_escape_string($this->username)."'", $this->connection) or die(mysql_error());
  59.        if($this->info = mysql_fetch_assoc($result)) {
  60.            return true;      // record found  
  61.         }
  62.         else {
  63.         return false;    
  64.         }
  65.                      
  66.      $this->db_disconnect() ;
  67.        
  68. }
  69. }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement