Guest User

Untitled

a guest
Sep 1st, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. <?php
  2.  
  3. // Connects to your Database
  4.  
  5. mysql_connect("localhost", "user", "pass") or die(mysql_error());
  6.  
  7. mysql_select_db("db_name") or die(mysql_error());
  8.  
  9.  
  10. //Checks if there is a login cookie
  11.  
  12. if(isset($_COOKIE['ID_my_site']))
  13.  
  14.  
  15. //if there is, it logs you in and directes you to the members page
  16.  
  17. {
  18. $username = $_COOKIE['ID_my_site'];
  19.  
  20. $pass = $_COOKIE['Key_my_site'];
  21.  
  22. $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
  23.  
  24. while($info = mysql_fetch_array( $check ))
  25.  
  26. {
  27.  
  28. if ($pass != $info['password'])
  29.  
  30. {
  31.  
  32. }
  33.  
  34. else
  35.  
  36. {
  37.  
  38. header("Location: members.php");
  39.  
  40.  
  41.  
  42. }
  43.  
  44. }
  45.  
  46. }
  47.  
  48.  
  49. //if the login form is submitted
  50.  
  51. if (isset($_POST['submit'])) { // if form has been submitted
  52.  
  53.  
  54.  
  55. // makes sure they filled it in
  56.  
  57. if(!$_POST['username'] | !$_POST['pass']) {
  58.  
  59. die('You did not fill in a required field.');
  60.  
  61. }
  62.  
  63. // checks it against the database
  64.  
  65.  
  66.  
  67. if (!get_magic_quotes_gpc()) {
  68.  
  69. $_POST['email'] = addslashes($_POST['email']);
  70.  
  71. }
  72.  
  73. $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
  74.  
  75.  
  76.  
  77. //Gives error if user dosen't exist
  78.  
  79. $check2 = mysql_num_rows($check);
  80.  
  81. if ($check2 == 0) {
  82.  
  83. die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>');
  84.  
  85. }
  86.  
  87. while($info = mysql_fetch_array( $check ))
  88.  
  89. {
  90.  
  91. $_POST['pass'] = stripslashes($_POST['pass']);
  92.  
  93. $info['password'] = stripslashes($info['password']);
  94.  
  95. $_POST['pass'] = md5($_POST['pass']);
  96.  
  97.  
  98.  
  99. //gives error if the password is wrong
  100.  
  101. if ($_POST['pass'] != $info['password']) {
  102.  
  103. die('Incorrect password, please try again.');
  104.  
  105. }
  106. else
  107.  
  108. {
  109.  
  110.  
  111. // if login is ok then we add a cookie
  112.  
  113. $_POST['username'] = stripslashes($_POST['username']);
  114.  
  115. $hour = time() + 3600;
  116.  
  117. setcookie(ID_my_site, $_POST['username'], $hour);
  118.  
  119. setcookie(Key_my_site, $_POST['pass'], $hour);
  120.  
  121.  
  122.  
  123. //then redirect them to the members area
  124.  
  125. header("Location: members.php");
  126.  
  127. }
  128.  
  129. }
  130.  
  131. }
  132.  
  133. else
  134.  
  135. {
  136.  
  137.  
  138.  
  139. // if they are not logged in
  140.  
  141. ?>
  142.  
  143. <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  144.  
  145. <table border="0">
  146.  
  147. <tr><td colspan=2><h1>Login</h1></td></tr>
  148.  
  149. <tr><td>Username:</td><td>
  150.  
  151. <input type="text" name="username" maxlength="40">
  152.  
  153. </td></tr>
  154.  
  155. <tr><td>Password:</td><td>
  156.  
  157. <input type="password" name="pass" maxlength="50">
  158.  
  159. </td></tr>
  160.  
  161. <tr><td colspan="2" align="right">
  162.  
  163. <input type="submit" name="submit" value="Login">
  164.  
  165. </td></tr>
  166.  
  167. </table>
  168.  
  169. </form>
  170.  
  171. <?php
  172.  
  173. }
  174.  
  175.  
  176.  
  177. ?>
Add Comment
Please, Sign In to add comment