Advertisement
sqpp

Untitled

Dec 9th, 2017
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.99 KB | None | 0 0
  1. <?php
  2. session_start();
  3. require_once 'mydbms.php';
  4. $DBcon=mysqli_connect('localhost','batab','kina','kina');
  5.  
  6. if (isset($_SESSION['userSession'])!="") {
  7.  header("Location: home.php");
  8.  exit;
  9. }
  10.  
  11. include_once $_SERVER['DOCUMENT_ROOT'] . '/Kina/securimage/securimage.php';
  12. $securimage = new Securimage();
  13.  
  14. if (isset($_POST['btn-login'])) {
  15.  
  16.  if ($securimage->check($_POST['captcha_code']) == false) {
  17.       // the code was incorrect
  18.       // you should handle the error so that the form processor doesn't continue
  19.       // or you can use the following code if there is no validation or you do not know how
  20.       echo "The security code entered was incorrect.<br /><br />";
  21.       echo "Please go <a href='javascript:history.go(-1)'>back</a> and try again.";
  22.       exit;
  23.     }
  24.  
  25.  $username = strip_tags($_POST['username']);
  26.  $password = strip_tags($_POST['password']);
  27.  
  28.  $username = $DBcon->real_escape_string($username);
  29.  $password = $DBcon->real_escape_string($password);
  30.  
  31.  $query = $DBcon->query("SELECT user_id, username, password FROM users WHERE username='$username'");
  32.  $row=$query->fetch_array();
  33.  
  34.  
  35.  
  36.   $_SESSION['user_id']=$row['user_id'];
  37. $_SESSION['role']=$row['role'];
  38.  
  39.  
  40.  
  41.  $count = $query->num_rows; // if email/password are correct returns must be 1 row
  42.  
  43.  if($count==1)
  44.  {
  45.                 if ($row['role']=="administrator")
  46.             {
  47.  
  48.                                header ("location: home.php");
  49.                              
  50.             }
  51.             else if ($row['role']=="user")
  52.             {
  53.                                $_SESSION['role']=$row['role'];
  54.  
  55.                                header ("location: 404.php");
  56.                              
  57.  
  58.             }
  59.  }
  60.      
  61.  
  62.  
  63.  
  64.  if (password_verify($password, $row['password']) && $count==1) {
  65.   $_SESSION['userSession'] = $row['user_id'];
  66.   header("Location: index.php");
  67.  } else {
  68.   $msg = "<div class='alert alert-danger'>
  69.     <span class='glyphicon glyphicon-info-sign'></span> &nbsp; Invalid Username or Password !
  70.    </div>";
  71.  }
  72.  $DBcon->close();
  73. }
  74. ?>
  75. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  76. <html xmlns="http://www.w3.org/1999/xhtml">
  77. <head>
  78. <script src='https://www.google.com/recaptcha/api.js'></script>
  79. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  80. <title>Coding Cage - Login & Registration System</title>
  81. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
  82. <link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
  83. <link rel="stylesheet" href="style.css" type="text/css" />
  84. </head>
  85. <body>
  86.  
  87. <div class="signin-form">
  88.  
  89.  <div class="container">
  90.      
  91.        
  92.        <form class="form-signin" method="post" id="login-form">
  93.      
  94.         <h2 class="form-signin-heading">Sign In.</h2><hr />
  95.        
  96.         <?php
  97.   if(isset($msg)){
  98.    echo $msg;
  99.   }
  100.   ?>
  101.        
  102.         <div class="form-group">
  103.         <input type="text" class="form-control" placeholder="Felhasználónév" name="username" required />
  104.         <span id="check-e"></span>
  105.         </div>
  106.        
  107.         <div class="form-group">
  108.         <input type="password" class="form-control" placeholder="Password" name="password" required />
  109.         </div>
  110.        
  111.       <hr />
  112.         <img id="captcha" src="/Kina/securimage/securimage_show.php" alt="CAPTCHA Image" />
  113.         <input type="text" name="captcha_code" size="10" maxlength="6" />
  114.     <a href="#" onclick="document.getElementById('captcha').src = '/Kina/securimage/securimage_show.php?' + Math.random(); return false">[ Different Image ]</a>
  115.         <div class="form-group">
  116.             <button type="submit" class="btn btn-default" name="btn-login" id="btn-login">
  117.       <span class="glyphicon glyphicon-log-in"></span> &nbsp; Sign In
  118.    </button>
  119.            
  120.             <a href="register.php" class="btn btn-default" style="float:right;">Sign UP Here</a>
  121.            
  122.         </div>  
  123.        
  124.        
  125.      
  126.       </form>
  127.  
  128.     </div>
  129.    
  130. </div>
  131.  
  132. </body>
  133. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement