Guest User

Untitled

a guest
Apr 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. cookie check
  2. -------------------
  3. <?
  4. // Connects to your Database
  5. require("dbconfig.php");
  6. //checks cookies to make sure they are logged in
  7. if(isset($_COOKIE['ID_my_site']))
  8. {
  9. $username = $_COOKIE['ID_my_site'];
  10. $pass = $_COOKIE['Key_my_site'];
  11. $check = mysql_query("SELECT * FROM users WHERE user = '$username'")or die(mysql_error());
  12. while($info = mysql_fetch_array( $check ))
  13. {
  14.  
  15. //if the cookie has the wrong password, they are taken to the login page
  16. if ($pass != $info['password'])
  17. { header("Location: index.php");
  18. }
  19.  
  20. //otherwise they are shown the admin area
  21. else
  22. {
  23.  
  24. }
  25. }
  26. }
  27. else
  28.  
  29. //if the cookie does not exist, they are taken to the login screen
  30. {
  31. header("Location: index.php");
  32. }
  33. ?>
  34.  
  35. login.php
  36. -------------------------------
  37. <?php
  38. require("dbconfig.php");
  39. $un=$_POST['username'];
  40. $pw=$_POST['password'];
  41.  
  42. $query = mysql_query("SELECT * FROM users WHERE user ='$un' AND password='$pw'",$link);
  43. $count=mysql_num_rows($query);
  44.  
  45. // If result matched $myusername and $mypassword, table row must be 1 row
  46.  
  47. if($count==1){
  48. // Register $username, $password and redirect to file "login_success.php"
  49. session_register("un");
  50. session_register("pw");
  51.  
  52. // if login is ok then we add a cookie
  53. $_POST['username'] = stripslashes($_POST['username']);
  54. $hour = time() + 3600;
  55. setcookie(ID_my_site, $_POST['username'], $hour);
  56. setcookie(Key_my_site, $_POST['password'], $hour);
  57.  
  58. //then redirect them to the members area
  59. header("Location: index2.php");
  60.  
  61. }else{
  62. header("Location: index.php");
  63.  
  64. }
  65.  
  66. ob_end_flush()
  67. ?>
Add Comment
Please, Sign In to add comment