Last active
October 21, 2015 07:08
-
-
Save salmanshahid527/8cb2d60736e1a69d3788 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include("DB.php"); | |
class User extends DB | |
{ | |
private $user_id; | |
private $first_name; | |
function __construct(){ | |
} | |
public function __seter($name, $value) { | |
$restricted = array("login"); | |
if(in_array($name, $restricted)) | |
{ | |
throw new Exception("Un-Authorized Access of Property $name"); | |
} | |
$method = "set_$name"; | |
if (!method_exists($this, $method)) { | |
throw new Exception("SET:Property $name does not exist"); | |
} | |
$this->$method($value); | |
} | |
public function __geter($name) { | |
$method = "get_$name"; | |
if (!method_exists($this, $method)) { | |
throw new Exception("GET:Property $name does not exist"); | |
} | |
return $this->$method(); | |
} | |
private function set_first_name($name) | |
{ | |
if(empty($name)) | |
throw new Exception("Empty first_name"); | |
else | |
$this->first_name = $name; | |
} | |
private function get_first_name() | |
{ | |
return $this->first_name; | |
} | |
public function login_user() | |
{ | |
$sql = " | |
SELECT * | |
FROM test_table | |
where email = $email | |
and password = $password | |
"; | |
try | |
{ | |
$response = DB::run($sql); | |
$row = $response->fetch(PDO::FETCH_OBJ); | |
$_SESSION['user_obj'] = serialize($row); | |
} | |
catch(Exception $px) | |
{ | |
echo($px->getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment