Guest User

Untitled

a guest
Apr 9th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.21 KB | None | 0 0
  1. <?php
  2. $_SESSION['lastPage'] = 2;
  3.  
  4. if(isset ($_GET['action']) && $_GET['action'] == 'logout') {
  5.     $_SESSION['username'] = "";
  6.     $_SESSION['user_id'] = "";
  7.     $_SESSION['admin'] = false;
  8.     header('Location: ?page=home');
  9. }
  10.  
  11. if(isset($_POST['user']) && isset($_POST['pass'])) {
  12.     $query = 'select * from users where nick="'.$_POST['user'].'" and password="'.md5($_POST['pass']).'"';
  13.     $result = mysql_query($query);
  14.  
  15.     if(mysql_num_rows($result) > 0) {
  16.         $_SESSION['user_id'] = mysql_result($result, 0, "id");
  17.         $_SESSION['username'] = mysql_result($result, 0, "name");
  18.  
  19.         if(mysql_result($result, 0, "admin") == "1")
  20.             $_SESSION['admin'] = true;
  21.        
  22.         header('Location: ?page=home');
  23.     }
  24.     else {
  25.         $error = "* Wrong username / password!";
  26.         showLoginForm($error);
  27.     }
  28. }
  29. else {
  30.     showLoginForm(null);
  31. }
  32.  
  33. function showLoginForm($error) {
  34.     ?>
  35.     <div class="mainContent" style="min-height: 495px;">
  36.         Please insert your login information:<br><br>
  37.         <form name="login" method="post" action="?page=login">
  38.             <table width="550" border="0" cellpadding="0" cellspacing="5" class="formulario">
  39.                 <tr>
  40.                     <td width="100">Username:</td>
  41.                     <td width="200"><input name="user" type="text" id="user"></td>
  42.                     <td width="250"></td>
  43.                 </tr>
  44.                 <tr>
  45.                     <td width="100">Password:</td>
  46.                     <td width="200"><input name="pass" type="password" id="pass"></td>
  47.                     <td width="250"></td>
  48.                 </tr>
  49.                 <tr>
  50.                     <td width="100"></td>
  51.                     <td width="200"><input type="submit" name="Submit" value="Login" style="width: 80px; height: 20px; margin-left: 2px; margin-top: 10px;"></td>
  52.                     <td width="250" style="padding-top: 10px;"><div class="error"><?php if(isset ($error)) { echo $error; } ?></div></td>
  53.                 </tr>
  54.             </table>
  55.         </form>
  56.         <br>
  57.         I kinda forgot my password!<br><br>
  58.         Not a member? Register <a href="?page=register">Here</a>!
  59.     </div>
  60.     <?php
  61. }
  62.  
  63.  
  64. ?>
Add Comment
Please, Sign In to add comment