#---------------------------------------------
# Create an index.php
#---------------------------------------------
login_verify($p['user'],$p['pass']);
if($_SESSION['access']){
header("Location:page.php");
}else{
echo "Access Denied!";
}
}
?>Login Here
#---------------------------------------------
# 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);
}
}
?>
Showing posts with label php. Show all posts
Showing posts with label php. Show all posts
LOGIN CLASS
Turn on all error message in php
Coding PHP is very cool but sometimes i thought my code was bug free... then its not.. I experience this in the module that I've written in my previous client, in my end it was running so smooth but when the client run it in their end lots of bugs showed up. Then after reading and searching some site about this, I found that there are many ways to get this bug shows. one of these are..
Just put on the top of your php code.
now i always put them on my code while testing...
Just put on the top of your php code.
error_reporting(E_ALL);
ini_set('display_errors', '1');
now i always put them on my code while testing...
Labels:
php
mysqli class query design
Class _mysqli{
function query($query){
$res = $this->mysqli->query($query);
$result = false;
if($res){
while($row = $res->fetch_assoc())
$result[] = $row;
return $result;
} else {
return $this->mysql->error;
}
}
function insert($query){
$this->mysqli->query($query);
return $this->mysqli->insert_id;
}
function update($query){
$this->mysqli->query($query);
return $this->mysqli->error;
}
function getnumrow($query){
$res = $this->mysqli->query($query);
return $res->num_rows;
}
}
Subscribe to:
Posts (Atom)
