Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* USR CLASS */
- class usr {
- private $connection;
- public function __construct($username,$password,$hash=true) {
- $this->username = $username;
- if($hash){
- $this->password = md5($password);
- }elseif(!$hash) {
- $this->password = $password;
- }
- }
- public function db_connect() {
- $this->connection = mysql_connect(USER_DB_SERVER, USER_DB_USERNAME, USER_DB_PASSWORD) or die(mysql_error());
- mysql_select_db(USER_DB_NAME, $this->connection) or die(mysql_error());
- }
- public function db_disconnect() {
- mysql_close( $this->connection );
- }
- public function _login() {
- $this->db_connect();
- $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());
- if($this->info = mysql_fetch_assoc($result)) {//if we did return a record
- return true; // logged in
- }
- else {
- return false;
- }
- $this->db_disconnect() ;
- }
- public function _logout() {
- setcookie('login',NULL,time()-100,'/'); // destroy some cookies.
- setcookie('username',NULL,time()-100,'/');
- setcookie('password',NULL,time()-100,'/');
- }
- public function set_cookies($expire) {
- setcookie('username',$this->username,$expire,'/'); // set some cookies.
- setcookie('password',$this->password,$expire,'/');
- setcookie('login',true,$expire,'/');
- }
- public function _query() {
- $this->db_connect();
- $result = mysql_query("SELECT * FROM ".PAGE_TABLE." WHERE username='".mysql_real_escape_string($this->username)."'", $this->connection) or die(mysql_error());
- if($this->info = mysql_fetch_assoc($result)) {
- return true; // record found
- }
- else {
- return false;
- }
- $this->db_disconnect() ;
- }
- }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement