Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.11 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['process']) and $_POST['process']==1) {
  3.     $pass = trim($_POST['pass']);
  4.    
  5.     $query = 'UPDATE members SET password = "'.$pass.'" WHERE id = "'.$_SESSION['id'].'"';
  6.                
  7.     if (mysql_query($query)) {
  8.         echo "Your password has now been created. You will be redirected to the home page now.";
  9.         echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=?p=main\">";
  10.     } else {
  11.         echo '<p style="color:#C00;">Error please report this.</p>';
  12.     }
  13. } else {
  14. if($_SESSION['id']){
  15.     $logouttime = 300;
  16.     $timenow = time();
  17.     $loggedtime = $timenow - $logouttime;
  18.     $query = mysql_query("UPDATE `members` SET `sitelogged` = '".$loggedtime."' WHERE `id`='".$_SESSION['id']."'") or die(mysql_error());
  19.     $isofflinequery = mysql_query("UPDATE `members` SET `online` = '0' WHERE `id`='".$_SESSION['id']."'") or die(mysql_error());
  20.     session_destroy();
  21.     echo "You are now logged out. Please come again soon.<br /><br />";
  22.     echo "You will be redirected in 3 seconds.";
  23.     echo "<META HTTP-EQUIV=Refresh CONTENT=\"3; URL=index.php\">";
  24. }else{
  25.     if(!$_POST['login']){
  26.         echo "<fieldset><legend><b>Login</b></legend>";
  27.         echo "<form method=\"POST\"><center><table border=\"0\" width=\"300\">";
  28.         echo "<tr><td align=\"right\" width=\"50%\"><b>Username:</b></td><td><input type=\"text\" name=\"username\" maxlength=\"24\"></td></tr>";
  29.         echo "<tr><td align=\"right\"><b>Password:</b></td><td><input type=\"password\" name=\"password\" maxlength=\"12\"></td></tr>";
  30.         echo "<tr><td></td><td><input type=\"submit\" name=\"login\" value=\"Login\"></td></tr>";
  31.         echo "</table></center></form>";
  32.         echo "</fieldset>";
  33.     }else{
  34.         $u = mysql_real_escape_string($_POST['username']);
  35.         $p = mysql_real_escape_string($_POST['password']);
  36.         $s = mysql_query("SELECT * FROM `members` WHERE `username`='".$u."'") or die(mysql_error());
  37.         $i = mysql_fetch_array($s);
  38.        
  39.         if($i['password'] == $p){
  40.             if (mysql_num_rows($s)) {
  41.                 $user = mysql_query("SELECT * FROM `members` WHERE `username`='".$i['username']."' AND `password`='".$i['password']."'") or die(mysql_error());
  42.                 $auser = mysql_fetch_array($user);
  43.                 $_SESSION['id'] = $auser['id'];
  44.                 $_SESSION['username'] = $auser['username'];
  45.                 $_SESSION['name'] = $auser['name'];
  46.                 if ($auser['admin'] == '1') {
  47.                     $_SESSION['admin'] = '1';
  48.                 } else {
  49.                     $_SESSION['admin'] = '0';
  50.                 }
  51.                 if ($i['password'] == '') {
  52.                     echo "This is your first time logging in. Please create a password:<br><br>";
  53.                     echo "<form name='guestbook' action='?p=login' method='POST'><table><tr><td>Password:</td>";
  54.                     echo "<td><input type='text' name='pass' /> <input type='hidden' name='process' value='1' />";
  55.                     echo "<input type='submit' value='Submit'></td></tr></table></form>";
  56.                 } else {
  57.                     echo "You are now logged in.<br /><br />";
  58.                     echo "You will be redirected in 3 seconds.";
  59.                     echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=index.php\">";
  60.                 }
  61.             } else {
  62.                 echo "This account does not exist. Click <a href='?p=login'>here</a> to retry.";
  63.             }
  64.         } else {
  65.             echo "The password you have entered is incorrect. Click <a href='?p=login'>here</a> to retry.";
  66.         }
  67.     }
  68. }
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement