hi,
i am having an issue i havent had before and cant see where i am going wrong.
i have an index.php with this at the top
Code: Select all
include("includes/config.php");
if (!$_SESSION["AUTH"]){
header("Location: login.php");
}Code: Select all
//base classes
$UserObj = User::getInstance();Code: Select all
if ($_POST && !empty($_POST["username"]) && !empty($_POST["password"])){
//login user
$UserObj->login($_POST["username"],$_POST["password"]);
if ($UserObj->isAuth()){
$_SESSION["AUTH"] = true;
header("Location: index.php");
}else{
$err = '<span class="gt-error">Incorrect Username and Password combination</span>';
}
}else{
$err="";
}Code: Select all
<?php echo $UserObj->getName();?>Code: Select all
object(User)#11 (12) { ["id:private"]=> NULL ["name:private"]=> NULL ["username:private"]=> NULL ["password:private"]=> NULL ["branchid:private"]=> NULL ["created:private"]=> NULL ["lastlogin:private"]=> NULL ["voucherslogged:private"]=> NULL ["edited:private"]=> NULL ["newuser:private"]=> NULL ["Auth:private"]=> NULL ["loaded:private"]=> NULL }Code: Select all
/*User Class*/
class User {
/*member vars*/
/*user table*/
private $id;
private $name;
private $username;
private $password;
private $branchid;
private $created;
private $lastlogin;
private $voucherslogged;
private $edited;
//new user?
private $newuser;
//auth
private $Auth;
private $loaded;
private static $instance;
/*member functions*/
// The singleton method
public static function getInstance()
{
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
// Prevent users to clone the instance
public function __clone()
{
trigger_error('Clone is not allowed.', E_USER_ERROR);
}
public function login($username,$password){
//lets login in the user
$sql = "select * from users where username = '".$username."' ";
$rs = query($sql);
if ($rs->RecordCount() > 0){
if ($rs)
while ($arr = $rs->FetchRow()) {
# process $arr
$this->id = $arr["id"];
$this->name = $arr["name"];
$this->username = $arr["username"];
$this->password = $arr["password"];
$this->branchid = $arr["branchid"];
$this->created = $arr["created"];
$this->lastlogin = $arr["lastlogin"];
$this->voucherslogged = $arr["vouchers_logged"];
$this->edited = $arr["edited"];
}
if($password == $this->password){
$this->Auth = true;
}else{
$this->Auth = false;
}
}else{
$this->Auth = false;
}
}
// A private constructor; prevents direct creation of object
private function __construct()
{
}
function __destructor(){
//nothing
}
public function isAuth(){
return $this->Auth;
}
public function getName(){
return $this->name;
}
}pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: