Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. if(isset($_COOKIE['ID_my_site']))
  2.  
  3. //if there is, it logs you in and directes you to the members page
  4.  
  5. { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: members.php"); } } }
  6.  
  7. //if the login form is submitted
  8.  
  9. if (isset($_POST['submit'])) {
  10.  
  11. // if form has been submitted
  12. // makes sure they filled it in
  13. if(!$_POST['username'] | !$_POST['pass']) {
  14. die('You did not fill in a required field.');
  15. }
  16. // checks it against the database
  17.  
  18. if (!get_magic_quotes_gpc()) {
  19. $_POST['email'] = addslashes($_POST['email']);
  20. }
  21. $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
  22.  
  23. //Gives error if user dosen't exist
  24. $check2 = mysql_num_rows($check);
  25. if ($check2 == 0) {
  26. die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
  27. }
  28. while($info = mysql_fetch_array( $check ))
  29. {
  30. $_POST['pass'] = stripslashes($_POST['pass']);
  31. $info['password'] = stripslashes($info['password']);
  32. $_POST['pass'] = md5($_POST['pass']);
  33.  
  34. //gives error if the password is wrong
  35. if ($_POST['pass'] != $info['password']) {
  36. die('Incorrect password, please try again.');
  37. }
  38. else { // if login is ok then we add a cookie
  39. $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area
  40. header("Location: members.php"); } } }
  41. else { // if they are not logged in
  42. ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement