Thanx! I know that something about OOP is not true to my mind, I need to shake it. Why am I doing this. First I use the template engine. Following user data after this data data file. Something is there actionUser.php:
$op = ''; IF (ISSET($_REQUEST['op'])){ $op = ADDSLASHES($_REQUEST['op']); } if ($op == 'AddUser'){ $Name = ADDSLASHES($_REQUEST['Name']) $Password = ADDSLASHES($_REQUEST['Password']) $MyUser->Add($Name, $Password) }
Then send the action to the class user.
User class has litle bit more features
class User{ private $SQL; public function __construct(){ $this->SQL = SQL::getInstance(); } public Function AddUser ($Name, $Password) { $sql_str ="INSERT INTO USER SET Name = '$Name', Password='$Password'"; $this->SQL->do_sql($sql_str); } public Function DelUser($UserID){ $sql_str = "DELETE FROM User WHERE UserID = '$UserID'"; $sql->do_sql($sql_str); } public Function Login($Login, $Password){ $sql_str = "SELECT * FROM User WHERE Login = '$Login' AND Password = '$Password' "; LIST($sql_result, $sql_count) = $this->SQL->do_sql($sql_str); if ($sql_count == 1){ $_SESSION["UserID"] = $this->SQL->result_strip($sql_result, 0, "AdminUserID"); $_SESSION["Login"] = $this->SQL->result_strip($sql_result, 0, "Login"); $sql_str = "UPDATE User SET LastLogin = NOW()"; $this->SQL->do_sql($sql_str); } } public Function Logout(){ $_SESSION = array(); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } session_destroy(); } }
Oop tester
source share