Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class mySQL
- {
- /*
- * You know this shit by now, Hopefully.
- */
- }
- class user
- {
- private $userId = 0, $loggedIn = false;
- public function __construct()
- {
- if( $_POST )
- {
- $this->_logIn();
- }
- $this->_checkSession();
- }
- public function isLoggedIn()
- {
- return $this->loggedIn;
- }
- private function _logIn()
- {
- $query = mysql_query('SELECT id FROM users WHERE username = "'.$_POST['username'].'" AND password = "'.$_POST['password'].'" LIMIT 1;');
- if( mysql_num_rows( $query ) > 0 )
- {
- $this->userId = mysql_result( $query, 0, 0 );
- mysql_query('INSERT INTO sessions (sessionId, userId)VALUES("'.session_id().'", "'.$this->userId.'");');
- }
- else
- {
- /*
- * you will not to do some more validation
- *
- */
- }
- }
- private function _checkSession()
- {
- $query = mysql_query('SELECT userId FROM sessions WHERE sessionId = "'.session_id().'" LIMIT 1;');
- if( mysql_num_rows( $query ) > 0 )
- {
- $this->loggedIn = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement