Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.51 KB | None | 0 0
  1. Everything else works except this.. it comes up with a header error -.- please help.
  2.  
  3.  
  4. <?php
  5.  // Connects to your Database
  6. include ("database.php");
  7.  
  8.  //Checks if there is a login cookie
  9.  if(isset($_COOKIE['ID_my_site']))
  10.  
  11.  //if there is, it logs you in and directes you to the members page
  12.  {  $username = $_COOKIE['ID_my_site'];
  13.     $pass = $_COOKIE['Key_my_site'];
  14.         $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
  15.     while($info = mysql_fetch_array( $check ))  
  16.         {
  17.         if ($pass != $info['password'])
  18.             {
  19.                         }
  20.         else
  21.             {
  22.             header("Location: members.php");
  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.  // if login is ok then we add a cookie
  59.      $_POST['username'] = stripslashes($_POST['username']);
  60.      $hour = time() + 3600;
  61.  setcookie(ID_my_site, $_POST['username'], $hour);
  62.  setcookie(Key_my_site, $_POST['pass'], $hour);  
  63.  
  64.  //then redirect them to the members area
  65.  header("Location: members.php");
  66.  }
  67.  }
  68.  }
  69.  else
  70.  {   
  71.  
  72.  // if they are not logged in
  73.  ?>
  74.  <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  75.  <table border="0">
  76.  <tr><td colspan=2><h1>Login</h1></td></tr>
  77.  <tr><td>Username:</td><td>
  78.  <input type="text" name="username" maxlength="40">
  79.  </td></tr>
  80.  <tr><td>Password:</td><td>
  81.  <input type="password" name="pass" maxlength="50">
  82.  </td></tr>
  83.  <tr><td colspan="2" align="right">
  84.  <input type="submit" name="submit" value="Login">
  85.  </td></tr>
  86.  </table>
  87.  </form>
  88.  <?php
  89.  }
  90.  
  91.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement