Advertisement
Guest User

Untitled

a guest
May 5th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. <?php
  2.  
  3. define("DB_HOST",'localhost');
  4. define("DB_USER",'root');
  5. define("DB_PASSWORD",'');
  6. define("DB_DATABASE",'admin_safeplace');
  7.  
  8.  
  9. ?>
  10.  
  11. <?php
  12.  
  13. class dbConnect
  14. {
  15.  
  16. public $conn;
  17. function __construct()
  18. {
  19.  
  20. //Initialize connection to database
  21. require_once('config.php');
  22. $this->conn=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);
  23. if(!$this->conn)
  24. {
  25. die('Cannot connect to the database');
  26.  
  27. }
  28. return $this->conn;
  29.  
  30. }
  31.  
  32.  
  33.  
  34. }
  35.  
  36. ?>
  37.  
  38. <?php
  39. require_once('dbConnect.php');
  40. session_start();
  41. class dbFunction
  42. {
  43.  
  44. function __construct()
  45. {
  46. //Connecting to the database
  47. $db=new dbConnect();
  48.  
  49.  
  50. }
  51. function login($email,$password) //Login Function
  52. {
  53.  
  54. $pass=md5($password);
  55. $sql="Select * from `super_user` where `email`='$email' AND `password`='$pass'";
  56. $res=mysqli_query($db->conn,$sql);
  57. $user_data = mysqli_fetch_array($res);
  58. $rowCount=mysqli_num_rows($res);
  59. if($rowCount==1)
  60. {
  61.  
  62. $_SESSION['login']=true;
  63. $_SESSION['email']=$user_data['email'];
  64. return TRUE;
  65.  
  66.  
  67. }
  68.  
  69. else
  70.  
  71. {
  72.  
  73. return FALSE;
  74.  
  75. }
  76.  
  77.  
  78. }
  79.  
  80.  
  81.  
  82. }
  83.  
  84.  
  85.  
  86. ?>
  87.  
  88. <!--Login Code-->
  89. <?php
  90.  
  91. $funObj = new dbFunction();
  92. if(isset($_POST['submit']))
  93. {
  94. $email = $_POST['email'];
  95. $password = $_POST['password'];
  96. $user = $funObj->login($email, $password);
  97. if ($user)
  98. {
  99. // Login Success
  100. header("location:list_users.php");
  101. }
  102. else
  103. {
  104. // Login Failed
  105. echo "<script>alert('Emailid / Password Not Match')</script>";
  106. }
  107.  
  108.  
  109. }
  110. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement