Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. <?php
  2. // Connects to your Database
  3. mysql_connect("host", "a8838560_admin", "pass") or die(mysql_error());
  4. mysql_select_db("main") or die(mysql_error());
  5.  
  6. echo "<LINK HREF=\"../../CSS.css\" REL=\"stylesheet\" TYPE=\"text/css\">";
  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. {
  13. $username = $_COOKIE['ID_my_site'];
  14. $pass = $_COOKIE['Key_my_site'];
  15. $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
  16. while($info = mysql_fetch_array( $check ))
  17. {
  18. if ($pass != $info['password'])
  19. {
  20. }
  21. else
  22. {
  23. header("Location: Home.php");
  24.  
  25. }
  26. }
  27. }
  28.  
  29. //if the login form is submitted
  30. if (isset($_POST['submit'])) { // if form has been submitted
  31.  
  32. // makes sure they filled it in
  33. if(!$_POST['username'] | !$_POST['pass']) {
  34. die('You did not fill in a required field.');
  35. }
  36. // checks it against the database
  37.  
  38. if (!get_magic_quotes_gpc()) {
  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. die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
  47. }
  48. while($info = mysql_fetch_array( $check ))
  49. {
  50. $_POST['pass'] = stripslashes($_POST['pass']);
  51. $info['password'] = stripslashes($info['password']);
  52. $_POST['pass'] = $_POST['pass'];
  53.  
  54. //gives error if the password is wrong
  55. if ($_POST['pass'] != $info['password']) {
  56. die('Incorrect password, please try again.');
  57. }
  58. else
  59. {
  60.  
  61. // if login is ok then we add a cookie
  62. $_POST['username'] = stripslashes($_POST['username']);
  63. $hour = time() + 3600;
  64. setcookie('ID_my_site', $_POST['username'], $hour);
  65. setcookie('Key_my_site', $_POST['pass'], $hour);
  66.  
  67. //then redirect them to the members area
  68. header("Location: Home.php");
  69. }
  70. }
  71. }
  72. else
  73. {
  74.  
  75. // if they are not logged in
  76. ?>
  77. <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  78. <table border="0">
  79. <tr><td colspan=2><h1>Login</h1></td></tr>
  80. <tr><td>Username:</td><td>
  81. <input type="text" name="username" maxlength="40">
  82. </td></tr>
  83. <tr><td>Password:</td><td>
  84. <input type="password" name="pass" maxlength="50">
  85. </td></tr>
  86. <tr><td colspan="2" align="right">
  87. <input type="submit" name="submit" value="Login">
  88. </td></tr>
  89. </table>
  90. </form>
  91. <?php
  92. }
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement