Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define("DB_HOST",'localhost');
- define("DB_USER",'root');
- define("DB_PASSWORD",'');
- define("DB_DATABASE",'admin_safeplace');
- ?>
- <?php
- class dbConnect
- {
- public $conn;
- function __construct()
- {
- //Initialize connection to database
- require_once('config.php');
- $this->conn=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);
- if(!$this->conn)
- {
- die('Cannot connect to the database');
- }
- return $this->conn;
- }
- }
- ?>
- <?php
- require_once('dbConnect.php');
- session_start();
- class dbFunction
- {
- function __construct()
- {
- //Connecting to the database
- $db=new dbConnect();
- }
- function login($email,$password) //Login Function
- {
- $pass=md5($password);
- $sql="Select * from `super_user` where `email`='$email' AND `password`='$pass'";
- $res=mysqli_query($db->conn,$sql);
- $user_data = mysqli_fetch_array($res);
- $rowCount=mysqli_num_rows($res);
- if($rowCount==1)
- {
- $_SESSION['login']=true;
- $_SESSION['email']=$user_data['email'];
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- }
- ?>
- <!--Login Code-->
- <?php
- $funObj = new dbFunction();
- if(isset($_POST['submit']))
- {
- $email = $_POST['email'];
- $password = $_POST['password'];
- $user = $funObj->login($email, $password);
- if ($user)
- {
- // Login Success
- header("location:list_users.php");
- }
- else
- {
- // Login Failed
- echo "<script>alert('Emailid / Password Not Match')</script>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement