Guest User

Untitled

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