Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 KB | None | 0 0
  1. <?php
  2. session_start();
  3. require_once('../includes/config.php');
  4. $conn=mysql_connect(DB_HOST,DB_USER,DB_PASS);
  5. mysql_select_db(DB_BASE);
  6. require_once('../classes/admin.class.php');
  7. require_once('../classes/sessions.class.php');
  8. $admin = new Admin();
  9. $sessions = new Sessions();
  10.  
  11. function protect($string) {
  12.   $string = trim(mysql_escape_string($string));
  13.   return $string;
  14. }
  15.  
  16. if (isset($_POST['loginSubmit']) && $_POST['loginClick'] == 1) {
  17.   $errors = array();
  18.   if(empty($_POST['username'])) {
  19.     $errors['username'] = 'You must provide your username.';
  20.   }
  21.   if(empty($_POST['password'])) {
  22.     $errors['password'] = 'You must provide your password.';
  23.   }
  24.   if(empty($errors)) {
  25.     $username = protect($_POST['username']);
  26.     $password = protect($_POST['password']);
  27.  
  28.     //First check to make sure that admin exists
  29.     $adminExists = $admin->adminExists($username, $password);
  30.     //If admin does exist, check to see if they are already loggedin
  31.     if ($adminExists['exists'] == 1) {
  32.         $uid = $adminExists['uid'];
  33.         $logCheck = $admin->adminLoggedin($uid);
  34.         //If they are already logged in, log them out and then log them back in
  35.         if ($logCheck['count'] == 1) {
  36.             $id = $logCheck['logID'];
  37.             $sessions->adminLogout($id);
  38.             $sessions->adminLogin($uid);
  39.             header("Location:main.php");
  40.         }
  41.         else {
  42.             $sessions->adminLogin($uid);
  43.             header("Location:main.php");
  44.         }
  45.     }
  46.     else {
  47.         $errors['notExist'] = 'The username and/or password you\'ve provided are incorrect. Please try again.';
  48.     }
  49.   }
  50. }
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement