Guest User

Untitled

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