query("SET NAMES 'utf8'"); //------------------------------------------------------------------------------------------------- class mysql_manager{ var $db_name; // az adatbázis neve var $link; // a kapcsolat értéke var $akt_db; // az aktuális adatbázis var $akt_tabla; // az aktuális tábla var $error; // MySQL hibajelzés var $success; // a kapcsolódás sikerességének vizsgálata function mysql_manager($server='localhost',$username,$password,$db_name){ $result = false; $this->link = @mysql_connect($server,$username,$password); if ($this->link==true){ $this->db_name = $db_name; $this->select_db(); $this->success=True; $result = True; }else{ $this->success=False; $this->error=mysql_error(); $result = False; } } function set_charset($charset){ mysql_set_charset($charset,$this->link); } function select_db(){ $this->akt_db = @mysql_select_db($this->db_name,$this->link); $this->error=mysql_error(); } function query($sql){ $result = @mysql_query($sql,$this->link); $this->error=mysql_error(); return $result; } function read($res, $type=3){ if ($res<>NULL){ if($type==1) $result=@mysql_fetch_object($res); if($type==2) $result=@mysql_fetch_array($res); if($type==3) $result=@mysql_fetch_assoc($res); } return $result; } function getrecord($sql, $type=3){ $row = $this->read($this->query($sql), $type); return $row; } function num_rows($res){ $count=@mysql_num_rows($res); $this->error=mysql_error(); return $count; } function error(){ $error_str = "\n\nMysql Error\n\n"; $error_str .= "\nMYSQL ERROR:
\n".$this->error; $error_str .= "\n"; return $error_str; } } ?> MM = $MM; $this->sys = $sys; @session_start(); if (!isset($_SESSION["logged"])) { $this->session_defaults(); } } function session_defaults() { @session_start(); $_SESSION["logged"] = false; $_SESSION["user_id"] = 0; $_SESSION["username"] = ""; $_SESSION["fullname"] = ""; } function checkLogin($username,$password) { $username = mysql_escape_string($username); $password = mysql_escape_string(md5($password)); $res = $this->MM->query("SELECT * FROM ".$this->sys["mysql_table_prefix"]."_administrators WHERE username='$username' AND password='$password'"); if ($res && $this->MM->num_rows($res)) { $row = $this->MM->read($res); $this->setSession($row); return true; } else { $this->failed = true; return false; } } function setSession($row, $init = true) { @session_start(); $_SESSION["user_id"] = (int)$row["id"]; $_SESSION["username"] = htmlspecialchars($row["username"]); $_SESSION["fullname"] = htmlspecialchars($row["fullname"]); $_SESSION["logged"] = true; if ($init && (int)$row["id"]) { $this->MM->query("UPDATE ".$this->sys["mysql_table_prefix"]."_administrators SET login_date=NOW(), session='".session_id()."' WHERE id='".(int)$row["id"]."'"); } } function checkSession() { @session_start(); $username = $_SESSION["username"]; $session = session_id(); $res = $this->MM->query("SELECT * FROM ".$this->sys["mysql_table_prefix"]."_administrators WHERE username='$username' AND session='$session'"); if ($res && $this->MM->num_rows($res)) { return true; } else { $this->session_defaults(); return false; } } function authenticate($username, $password) { @session_start(); $ret = $this->checkLogin($username,$password); if (!$ret) { $_SESSION = array(); $this->session_defaults(); } return $ret; } function verify() { return $this->checkSession(); } function logout() { @session_start(); $_SESSION = array(); $this->session_defaults(); } } ?>