Advertisement
Guest User

Untitled

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