Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.07 KB | None | 0 0
  1. <?php
  2.       session_start();
  3.       print_r($_SESSION);
  4.        
  5.       if(isset($_POST['login'])){
  6.               //retrieve form data
  7.               $email = $_POST['email'];
  8.               $password = $_POST['password'];
  9.              
  10.               //connect to database
  11.               $DBHOST = 'localhost';
  12.               $DBUSERNAME = 'root';
  13.               $DBPASSWORD = '';
  14.               $DB = 'jobx';
  15.              
  16.               $link = mysqli_connect($DBHOST,$DBUSERNAME,$DBPASSWORD,$DB);
  17.        
  18.               //match the username and password entered with database record
  19.               $query = 'SELECT * FROM `xuser` WHERE `email` = "' . $email . '" AND `password` = /*SHA*/("' . $password . '")';
  20.               $result = mysqli_query($link,$query) or die(mysqli_error($link));
  21.        
  22.               //if record is found, store id and name into session
  23.               if(mysqli_num_rows($result) >0){
  24.                       $row = mysqli_fetch_array($result);
  25.                       $_SESSION['role_id'] = $row['role_id'];
  26.                       $_SESSION['email'] = $row['email'];
  27.                       $_SESSION['logged_in'] = true;
  28.                       $_SESSION['user_info'] = $row['name'];
  29.              
  30.                       switch($_SESSION['role_id'])
  31.                       {
  32.                                       case 1:        
  33.                                               header("location: index.html");
  34.                                       break;
  35.                                       case 2:        
  36.                                               header("location: index2.html");
  37.                                       break;
  38.                                       default:              
  39.                                               header("location: index3.html");
  40.                                       break;
  41.                       }
  42.               }
  43.               else{ //record not found
  44.                       echo '<p class="error">Sorry, you must enter a valid email and password to log in.<a href="login.php">Back</a></p>';
  45.               }
  46.       }
  47.        
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement