Advertisement
gitlez

YA: Login Script Fixes 20120718042308AAQcU81 WOC

Jul 18th, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if(isset($_POST['Submit'])){
  4.     include 'connection/conn.php';
  5.     $database="issuelog";
  6.     $selectdb = mysql_selectdb($database);
  7.     if ($selectdb){
  8.         echo "Selected";
  9.         $UserName = $_POST['username'];
  10.         $Password = $_POST['password'];
  11.         $table = "userreg";
  12.         $sql = "SELECT UserName FROM $table WHERE UserName='{$UserName}' AND Password='{$Password}' LIMIT 1";
  13.         $results=mysql_query($sql, $conn);
  14.         if( $results && mysql_num_rows($results) === 1){
  15.             $_SESSION['username'] = $UserName;
  16.             $_SESSION['password'] = $Password;
  17.             if( !headers_sent()){
  18.                 header("Location: login_success.php");
  19.                 exit;
  20.             }else{
  21.                 echo '<meta http-equiv="refresh" content="0; url=login_success.php"/>');
  22.                 echo '<script>document.location.href="login_success.php";</script>';
  23.                 exit;
  24.             }
  25.         } else if( !$results ){
  26.             echo 'Internal Server Error';
  27.         } else {
  28.             echo "Wrong Username or Password.";
  29.         }
  30.     }
  31. }
  32. ?>
  33. login_success.php
  34. <?php
  35. session_start();
  36. if(!isset($_SESSION['username'])){
  37.     header("Location: login.php");
  38. }
  39. ?>
  40. <html>
  41.     <body>
  42.         Login Successful
  43.     </body>
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement