SHARE
TWEET

Untitled

a guest May 22nd, 2017 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  <?php
  2.  // Connects to your Database
  3.  mysql_connect("localhost", "dannyf_admin", "**HIDDEN**") or die(mysql_error());
  4.  mysql_select_db("dannyf_users") 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.         die('You did not fill in a required field.');
  33.     }
  34.     // checks it against the database
  35.  
  36.     if (!get_magic_quotes_gpc()) {
  37.         $_POST['email'] = addslashes($_POST['email']);
  38.     }
  39.     $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
  40.  
  41.  //Gives error if user dosen't exist
  42.  $check2 = mysql_num_rows($check);
  43.  if ($check2 == 0) {
  44.         die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
  45.                 }
  46.  while($info = mysql_fetch_array( $check ))    
  47.  {
  48.  $_POST['pass'] = stripslashes($_POST['pass']);
  49.     $info['password'] = stripslashes($info['password']);
  50.     $_POST['pass'] = md5($_POST['pass']);
  51.  
  52.  //gives error if the password is wrong
  53.     if ($_POST['pass'] != $info['password']) {
  54.         die('Incorrect password, please try again.');
  55.     }
  56.   else
  57.  {
  58.  
  59.  // if login is ok then we add a cookie
  60.      $_POST['username'] = stripslashes($_POST['username']);
  61.      $hour = time() + 3600;
  62.  setcookie(ID_my_site, $_POST['username'], $hour);
  63.  setcookie(Key_my_site, $_POST['pass'], $hour);  
  64.  
  65.  //then redirect them to the members area
  66.  header("Location: members.php");
  67.  }
  68.  }
  69.  }
  70.  else
  71. {    
  72.  
  73.  // if they are not logged in
  74.  ?>
  75.  <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  76.  <table border="0">
  77.  <tr><td colspan=2><h1>Login</h1></td></tr>
  78.  <tr><td>Username:</td><td>
  79.  <input type="text" name="username" maxlength="40">
  80.  </td></tr>
  81.  <tr><td>Password:</td><td>
  82.  <input type="password" name="pass" maxlength="50">
  83.  </td></tr>
  84.  <tr><td colspan="2" align="right">
  85.  <input type="submit" name="submit" value="Login">
  86.  </td></tr>
  87.  </table>
  88.  </form>
  89.  <?php
  90.  }
  91.  
  92.  ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top