Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php
  2.  
  3.     class mySQL
  4.     {
  5.        
  6.         /*
  7.          * You know this shit by now, Hopefully.
  8.          */
  9.        
  10.     }
  11.    
  12.     class user
  13.     {
  14.        
  15.         private $userId = 0, $loggedIn = false;
  16.        
  17.         public function __construct()
  18.         {
  19.            
  20.             if( $_POST )
  21.             {
  22.                
  23.                 $this->_logIn();
  24.                
  25.             }
  26.            
  27.             $this->_checkSession();
  28.            
  29.         }
  30.        
  31.         public function isLoggedIn()
  32.         {
  33.            
  34.             return $this->loggedIn;
  35.            
  36.         }
  37.        
  38.         private function _logIn()
  39.         {
  40.            
  41.             $query = mysql_query('SELECT id FROM users WHERE username = "'.$_POST['username'].'" AND password = "'.$_POST['password'].'" LIMIT 1;');
  42.            
  43.             if( mysql_num_rows( $query ) > 0 )
  44.             {
  45.                
  46.                 $this->userId = mysql_result( $query, 0, 0 );
  47.                
  48.                 mysql_query('INSERT INTO sessions (sessionId, userId)VALUES("'.session_id().'", "'.$this->userId.'");');
  49.                                
  50.             }
  51.             else
  52.             {
  53.                
  54.                 /*
  55.                  * you will not to do some more validation
  56.                  *
  57.                  */
  58.                
  59.             }
  60.            
  61.         }
  62.        
  63.         private function _checkSession()
  64.         {
  65.            
  66.             $query = mysql_query('SELECT userId FROM sessions WHERE sessionId = "'.session_id().'" LIMIT 1;');
  67.            
  68.             if( mysql_num_rows( $query ) > 0 )
  69.             {
  70.                
  71.                 $this->loggedIn = true;
  72.                
  73.             }
  74.            
  75.         }
  76.        
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement