Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2.  
  3. if(!isset($_SESSION['logged_in']) || empty($_SESSION['logged_in']))
  4. {
  5.     // If user is not authenticated redirect to authentication page
  6.     if (!$_SESSION['logged_in'])
  7.         header("Location: localhost/login.htm");
  8. }
  9.  
  10.  $user = addslashes($_POST['username']);
  11.  $pass = md5($_POST['password']);
  12.  
  13.  //set the database connection variables
  14.  
  15.  $dbHost = "localhost";
  16.  $dbUser = "webuser";
  17.  $dbPass = "";
  18.  $dbDatabase = "mydatabase";
  19.  
  20.  // connect to the database
  21.  
  22.  $db = mysql_connect($dbHost, $dbUser, $dbPass) or die("Error connecting to database.");
  23.  
  24.  mysql_select_db($dbDatabase, $db) or die("Coudln't select the databse.");
  25.  
  26.  $result=mysql_query("SELECT * FROM users WHERE userName='$user' AND userPass='$pass'", $db);
  27.  
  28.  $rowCheck = mysql_num_rows($result);
  29.  
  30.  if ($rowCheck > 0){
  31.   while($row = mysql_fetch_array($result)){
  32.    
  33.    // Start the session
  34.    session_start();
  35.    
  36.    // Set the session variables
  37.    $_SESSION['username'] = $row['user'];
  38.    $_SESSION['logged_in'] = true;
  39.  
  40.    // Successful login code will go here...
  41.    echo'Success!';
  42.  
  43.   // We will redirect the user to another page where we will make sure they're logged in.
  44.    // header("Location: checkLogin.php"); | No need for this
  45.   }
  46.  }
  47.  else
  48.  {
  49.    // if nothing is returned by the query, unsuccessful login code goes here.
  50.  
  51.    echo 'Incorrect login name or password. Please Try again.';
  52.  
  53. }
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement