login  Naam:   Wachtwoord: 
Registreer je!
 Forum

cookie probleem

Offline Rooonald - 19/05/2005 23:06
Avatar van RooonaldHTML interesse Ik gebruik op een website een login op basis van cookies, niet het meest betrouwbare volgens velen maar je moet ergens mee beginnen!

Die Login gebruik ik op meerdere pagina's met meerdere gebruikers, echter heb ik nu op 1 pagina een beperking nodig voor 3 gebruikers.

Het vervelende is dat alle ingelogde leden ook op die pagina kunnen komen nu....

Misschien dat een wat meer ervaren php' er wat op weet?

Dit is de scripting waar het over gaat:
  1. <?
  2. header("Pragma: ");
  3. header("Cache-Control: ");
  4. header("Expires: Mon, 26 Jul 1980 05:00:00 GMT");
  5. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  6. header("Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate");
  7. header("Cache-Control: post-check=0, pre-check=0", false);
  8. //set global variables
  9. global $username,$password;
  10.  
  11. //header("Pragma: no-cache");
  12. // EDIT HERE TO SUIT YOUR NEEDS
  13. //set usernames and passwords
  14. //only letters and numbers (no spaces) Known as can contain spaces
  15.  
  16. $uname[0] = "Ronald";
  17. $upass[0] = "pass";
  18. $known_as[0] = "Ronald user";
  19.  
  20. //additional users can be added
  21. $uname[1] = "Robert";
  22. $upass[1] = "pass";
  23. $known_as[1] = "Robert user";
  24.  
  25. $uname[2] = "Reinier";
  26. $upass[2] = "pass";
  27. $known_as[2] = "Reinier user";
  28.  
  29. $uname[3] = "Julian";
  30. $upass[3] = "Ipass";
  31. $known_as[3] = "Julian user";
  32.  
  33. $uname[4] = "Patrick";
  34. $upass[4] = "pass";
  35. $known_as[4] = "Patrick user";
  36.  
  37. $uname[5] = "Angelo";
  38. $upass[5] = "pass";
  39. $know_as[5] = "Angelo user";
  40.  
  41. $uname[6] = "Wilco";
  42. $upass[6] = "pass";
  43. $known_as[6] = "Wilco user";
  44.  
  45. $uname[7] = "Hans";
  46. $upass[7] = "pass";
  47. $known_as[7] = "Hans user";
  48.  
  49. $uname[8] = "Hetty";
  50. $upass[8] = "pass";
  51. $known_as[8] = "Hetty user";
  52.  
  53. $uname[9] = "Fajar";
  54. $upass[9] = "pass";
  55. $known_as[9] = "Fajar user";
  56.  
  57.  
  58.  
  59.  
  60. //the login page
  61. $login_page = "index.php";
  62. //where to go after login
  63. $success_page = "1.php";
  64. //the path to validate.php
  65. $validate_path = "full path to validate.php";
  66. //login failed error message
  67. $login_err = '<div class="12pxtitel" align="center">Je User Name of Password klopt niet.</b><br><br></div>';
  68. //no fields filled in
  69. $empty_err = '<div class="12pxtitel" align="center"><b>Je moet inloggen met je User Name en Password.</b><br><br></div>';
  70. //something entered that wasn't a letter or number error message
  71. $chr_err = '<div class="12pxtitel" align="center"><b>Probeer het nog eens.</b><br><br></div>';
  72. // DO NOT EDIT BELOW HERE
  73.  
  74. //if the form is empty and the cookie isn't set
  75. //then display error message the return to login
  76. if($username == "" && $password == "" && !isset($_COOKIE["this_cookie"])){
  77. print($empty_err);
  78. include($login_page);
  79. exit();
  80. }
  81.  
  82. //if the form is not empty and the cookie isn't set
  83. //then make sure that only letters and numbers are entered
  84. //if there are then display error message the return to login
  85. if($username != "" || $password != "" && !isset($_COOKIE["this_cookie"])){
  86. if (preg_match ("/[^a-zA-Z0-9]/", $username.$password)){
  87. print($chr_err);
  88. include($login_page);
  89. exit();
  90. }
  91. }
  92.  
  93. //if the cookie isn't set
  94. if (!isset($_COOKIE["this_cookie"]) ){
  95. $user_count = count($uname);
  96. $user_exists = false;
  97.  
  98. // check through all the users to see if they exist
  99. for ($i = 0; $i <= $user_count; $i++) {
  100. if ($uname[$i] == $username && $upass[$i] == $password){
  101. $user_id=$i;
  102. //$welcome_name = $known_as[$i];
  103. $user_exists = true;
  104. }
  105. }
  106.  
  107. if(!$user_exists){
  108. print ($login_err);
  109. include($login_page);
  110. exit();
  111. }
  112.  
  113. //if the login is correct then set the cookie
  114. $cookie_val=crypt($uname[$user_id]);
  115. //set the cookie so it dies when the browser is closed
  116. setcookie ("name", $known_as[$user_id], 0);
  117. setcookie ("this_cookie", $cookie_val, 0);
  118. header("Location: $success_page");
  119. exit();
  120. }
  121.  
  122. //if a user tries to access validate.php directly and they are logged in
  123. if($REQUEST_URI == $validate_path){
  124. echo "<html>\n<head>\n";
  125. echo "<title>You are logged in</title>\n";
  126. echo "</head>\n";
  127. echo "<body bgcolor=\"white\">\n";
  128. echo "You are logged in. <a href=\"".$success_page."\">Continue</a>\n";
  129. echo "</body>\n";
  130. echo "</html>\n";
  131.  
  132. }
  133.  
  134. ?>

3 antwoorden

Gesponsorde links
Offline Thomas - 20/05/2005 00:20
Avatar van Thomas Moderator Geef alle gebruikers rechten - dit kan heel simpel met bijvoorbeeld een getal dat aangeeft hoeveel rechten iemand heeft. Controleer op de pagina die je "extra" wilt beveiligen of iemand zijn rechten goed genoeg zijn (of het getal hoog genoeg is).
Offline Rooonald - 20/05/2005 00:23
Avatar van Rooonald HTML interesse Das idd wel wat, weet je een tutorial waar ik dat mee zou kunnen doen?
Offline Legolas - 20/05/2005 15:12
Avatar van Legolas Onbekend Hier: Klik
Is een rechtensys
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.21s