Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.60 KB | None | 0 0
  1. <h2>Login</h2>
  2. <br/><br/>
  3. <?php
  4.     //Checks if there is a login cookie
  5.     $cookieID = 'ID_kebax_dk_sell';
  6.     $cookieKey = 'Key_kebax_dk_sell';
  7.     if(isset($_COOKIE[$cookieID])) {
  8.         //if there is, it logs you in and directes you to the members page
  9.         $username = $_COOKIE[$cookieID];
  10.         $pass = $_COOKIE[$cookieKey];
  11.         $check = mysql_query("SELECT * FROM sell_users WHERE nickname = '".$username."'")or die(mysql_error());
  12.         while($info = mysql_fetch_array( $check )) {
  13.             if ($pass != $info['password']) {
  14.                 //fail -> nothing happens.
  15.             } else {
  16.                 $_SESSION['username'] = $username;
  17.                 echo 'Already logged in as '.$username;
  18.                 echo "<meta http-equiv=refresh content=\"1; URL=index.php\">";
  19.             }
  20.         }
  21.     } else if(isset($_POST['login'])) { // if form has been submitted
  22.         // makes sure they filled it in
  23.         if(!$_POST['username'] | !$_POST['password']) {
  24.             die('You did not fill in a required field.');
  25.         }
  26.         // checks it against the database
  27.         if (!get_magic_quotes_gpc()) {
  28.             $_POST['email'] = addslashes($_POST['email']);
  29.         }
  30.         $check = mysql_query("SELECT * FROM sell_users WHERE nickname = '".$_POST['username']."'")or die(mysql_error());
  31.    
  32.         //Gives error if user dosen't exist
  33.         $check2 = mysql_num_rows($check);
  34.         if ($check2 == 0) {
  35.             die('That user does not exist in our database.');
  36.         }
  37.    
  38.         while($info = mysql_fetch_array( $check )) {
  39.             $_POST['password'] = stripslashes($_POST['password']);
  40.             $info['password'] = stripslashes($info['password']);
  41.             $_POST['password'] = md5($_POST['password']);
  42.    
  43.             //gives error if the password is wrong
  44.             if ($_POST['password'] != $info['password']) {
  45.                 die('Incorrect password, please try again.');
  46.             }
  47.             else {
  48.                 // if login is ok then we add a cookie
  49.                 $_POST['username'] = stripslashes($_POST['username']);
  50.                 $hour = time() + 3600;
  51.                 setcookie(ID_kebax_dk_sell, $_POST['username'], $hour);
  52.                 setcookie(Key_kebax_dk_sell, $_POST['password'], $hour);
  53.                 $_SESSION['username'] = $_COOKIE['ID_kebax_dk_sell'];
  54.                 $username = $_COOKIE['ID_kebax_dk_sell'];
  55.    
  56.                 //then redirect them to the members area
  57.                 echo '<br/>Logged in successfully as '.$username.'...';
  58.                 //ob_end_flush();
  59.                 echo "<meta http-equiv=refresh content=\"1; URL=index.php\">";
  60.             }
  61.         }
  62.     }
  63.     else {
  64.     // if they are not logged in
  65.     echo ('
  66.         <form method="post" action="">
  67.             <input name="username" placeholder="Username..." type="text" maxlength="15" /><br/><br/>
  68.             <input name="password" placeholder="Password..." type="password" maxlength="20" /><br/><br/>
  69.             <input name="login" type="submit" value="Login" style="width:100px;">
  70.         </form>
  71.     ');
  72.     }
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement