Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. <?php
  2.  
  3. // Connects to your Database
  4.  
  5. mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
  6.  
  7. mysql_select_db("Database_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=add.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.  
  107. else
  108.  
  109. {
  110.  
  111.  
  112. // if login is ok then we add a cookie
  113.  
  114. $_POST['username'] = stripslashes($_POST['username']);
  115.  
  116. $hour = time() 3600;
  117.  
  118. setcookie(ID_my_site, $_POST['username'], $hour);
  119.  
  120. setcookie(Key_my_site, $_POST['pass'], $hour);
  121.  
  122.  
  123.  
  124. //then redirect them to the members area
  125.  
  126. header("Location: members.php");
  127.  
  128. }
  129.  
  130. }
  131.  
  132. }
  133.  
  134. else
  135.  
  136. {
  137.  
  138.  
  139.  
  140. // if they are not logged in
  141.  
  142. ?>
  143.  
  144. <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  145.  
  146. <table border="0">
  147.  
  148. <tr><td colspan=2><h1>Login</h1></td></tr>
  149.  
  150. <tr><td>Username:</td><td>
  151.  
  152. <input type="text" name="username" maxlength="40">
  153.  
  154. </td></tr>
  155.  
  156. <tr><td>Password:</td><td>
  157.  
  158. <input type="password" name="pass" maxlength="50">
  159.  
  160. </td></tr>
  161.  
  162. <tr><td colspan="2" align="right">
  163.  
  164. <input type="submit" name="submit" value="Login">
  165.  
  166. </td></tr>
  167.  
  168. </table>
  169.  
  170. </form>
  171.  
  172. <?php
  173.  
  174. }
  175.  
  176.  
  177.  
  178. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement