LOGIN CLASS

#---------------------------------------------
# Create an index.php
#---------------------------------------------


login_verify($p['user'],$p['pass']);

if($_SESSION['access']){
header("Location:page.php");
}else{
echo "Access Denied!";
}

}
?>


Login Here
















username
password





#---------------------------------------------
# Create a Php Class Name it as login.class.php
#---------------------------------------------
connect();
}

function __destruct() {
$this->disconnect();
}


#----------------------------
# LOGIN VERIFICATION
#----------------------------
function login_verify($username,$pass){
$logger = $this->getuser(htmlspecialchars(trim($username), ENT_QUOTES), htmlspecialchars(trim($pass), ENT_QUOTES));
if($logger[0]['Name']!=""){
$_SESSION['access'] = 1;
}else{
$_SESSION['access'] = 0;
}
}

/*************************************/
/* GET USER FUNCTION
/*************************************/
function getuser($user,$pass){
$sql = "Select * from users where Name like '$user' and Pass like '".md5($pass)."'";
$user = $this->query($sql);
return $user;
}



#----------------------------
# FUNCTION DB CONNNECT
#----------------------------
function connect() {
if ($_SERVER['HTTP_HOST'] == "localhost"){
$data = "localhost:root::td";
}

list($host, $user, $pass, $db) = explode(":", $data);
$this->cn = mysql_connect($host,$user,$pass);
mysql_selectdb($db,$this->cn);
}

#----------------------------
# QUERY FUNCTION
#----------------------------
function query($query){
$res = mysql_query($query);
$result = false;
if($res){
while($row = mysql_fetch_assoc($res))
$result[] = $row;
return $result;
} else {
return mysql_error();
}
}

#----------------------------
# DISCONNECT TO DB
#----------------------------
function disconnect(){
$this->cn = mysql_close($this->cn);
}


}

?>

No comments:

Post a Comment