article

Thursday, August 15, 2013

Simple Class login using php

Simple Class login using php 
 
<?
class UserAuth {
 var $user;
 var $pass;
 function isUserValid($user, $pass) {
  $sql = "select uid, first_name from $users_tb where user_name='$user' and password='$pass'";
  $result = mysql_query($sql);
  $rows   = mysql_num_rows($result);
  if($rows == 1) {
   $result_row = mysql_fetch_row($result);
   return $result_row;
  }
  else {
   return "0";
  }
 }
}
$userauth = new UserAuth;

session_start();
$user = $_POST['uname'];
$pass = $_POST['password'];
$val = $userauth->isUserValid($user, $pass);
if($val == "0") {
 header("Location: login.php");
}
else {
 $_SESSION['uid'] = $val[0];
 $_SESSION['fname'] = $val[1];
 $_SESSION['uname'] = $user;
 header("Location: SchedulerMain.php");
}
?>
<form name="scheduler_login" method="post" action="UserAuthController.php">
User name<input type=text size=15 name=uname>
Password<input type=password size=15 name=password>
<input type=submit name=submit value="Submit"> 
</form>

Related Post