Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.43 KB | None | 0 0
  1. <?php
  2.  
  3.     // Connects to your Database
  4.     include ("database.php");
  5.  
  6.     //Checks if there is a login cookie
  7.     if(isset($_COOKIE['ID_my_site']))
  8.     {
  9.         $username = mysql_real_escape_string( $_COOKIE['ID_my_site'] );
  10.         $pass = mysql_real_escape_string( $_COOKIE['Key_my_site'] );
  11.        
  12.         $check = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$pass'")or die(mysql_error());
  13.        
  14.         while($info = mysql_fetch_array( $check ))  
  15.         {
  16.             if ($pass == $info['password'])
  17.                 header("Location: members.php");
  18.         }
  19.     }
  20.    
  21.     //if the login form is submitted
  22.     if (isset($_POST['submit']))
  23.     { // if form has been submitted
  24.          
  25.         // makes sure they filled it in
  26.         if(!$_POST['username'] | !$_POST['pass'])
  27.             die('You did not fill in a required field.');
  28.  
  29.         // checks it against the database
  30.          if (!get_magic_quotes_gpc())
  31.             $_POST['email'] = addslashes($_POST['email']);
  32.        
  33.         $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
  34.          
  35.         //Gives error if user dosen't exist
  36.         $check2 = mysql_num_rows($check);
  37.            
  38.         if ($check2 == 0)
  39.             die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
  40.  
  41.         while($info = mysql_fetch_array( $check ))  
  42.         {
  43.             $_POST['pass'] = stripslashes($_POST['pass']);
  44.             $info['password'] = stripslashes($info['password']);
  45.             $_POST['pass'] = md5($_POST['pass']);
  46.      
  47.             //gives error if the password is wrong
  48.             if ($_POST['pass'] != $info['password'])
  49.                 die('Incorrect password, please try again.');
  50.             else
  51.             {
  52.                 // if login is ok then we add a cookie
  53.                 $_POST['username'] = stripslashes($_POST['username']);
  54.                 $hour = time() + 3600;
  55.                 setcookie(ID_my_site, $_POST['username'], $hour);
  56.                 setcookie(Key_my_site, $_POST['pass'], $hour);   
  57.    
  58.                 //then redirect them to the members area
  59.                 header("Location: members.php");
  60.             }
  61.         }
  62.     }
  63.     else
  64.     {    
  65.      
  66.      // if they are not logged in
  67.  ?>
  68.  <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  69.  <table border="0">
  70.  <tr><td colspan=2><h1>Login</h1></td></tr>
  71.  <tr><td>Username:</td><td>
  72.  <input type="text" name="username" maxlength="40">
  73.  </td></tr>
  74.  <tr><td>Password:</td><td>
  75.  <input type="password" name="pass" maxlength="50">
  76.  </td></tr>
  77.  <tr><td colspan="2" align="right">
  78.  <input type="submit" name="submit" value="Login">
  79.  </td></tr>
  80.  </table>
  81.  </form>
  82.  <?php
  83.  
  84.  }
  85.  
  86.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement