login  Naam:   Wachtwoord: 
Registreer je!
 Forum

beveiliging

Offline finduilas - 07/02/2006 20:37
Avatar van finduilasPHP gevorderde Hallo;

Ik heb op deze site een script gevonden om een pagina('s) te beveiligen.
Validate.php
  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. $uname[1] = "finduilas";
  16. $upass[1] = "test";
  17. $known_as[1] = "Admin";
  18. //additional users can be added
  19. //$uname[2] = "demo";
  20. //$upass[2] = "demo";
  21. //$known_as[2] = "demo";
  22.  
  23.  
  24. //the login page
  25. $login_page = "index.php";
  26. //where to go after login
  27. $success_page = "addmembers.php";
  28. //the path to validate.php
  29. $validate_path = "validate.php";
  30. //login failed error message
  31. $login_err = '<div align="center">Your User Name or Password was incorrect</b></div>';
  32. //no fields filled in
  33. $empty_err = '<div align="center"><b>You need to login with your User Name and Password</b></div>';
  34. //something entered that wasn't a letter or number error message
  35. $chr_err = '<div align="center"><b>Please retry</b></div>';
  36. // DO NOT EDIT BELOW HERE
  37.  
  38. //if the form is empty and the cookie isn't set
  39. //then display error message the return to login
  40. if($username == "" && $password == "" && !isset($_COOKIE["this_cookie"])){
  41. print($empty_err);
  42. include($login_page);
  43. exit();
  44. }
  45.  
  46. //if the form is not empty and the cookie isn't set
  47. //then make sure that only letters and numbers are entered
  48. //if there are then display error message the return to login
  49. if($username != "" || $password != "" && !isset($_COOKIE["this_cookie"])){
  50. if (preg_match ("/[^a-zA-Z0-9]/", $username.$password)){
  51. print($chr_err);
  52. include($login_page);
  53. exit();
  54. }
  55. }
  56.  
  57. //if the cookie isn't set
  58. if (!isset($_COOKIE["this_cookie"]) ){
  59. $user_count = count($uname);
  60. $user_exists = false;
  61.  
  62. // check through all the users to see if they exist
  63. for ($i = 1; $i <= $user_count; $i++) {
  64. if ($uname[$i] == $username && $upass[$i] == $password){
  65. $user_id=$i;
  66. //$welcome_name = $known_as[$i];
  67. $user_exists = true;
  68. }
  69. }
  70.  
  71. if(!$user_exists){
  72. print ($login_err);
  73. include($login_page);
  74. exit();
  75. }
  76.  
  77. //if the login is correct then set the cookie
  78. $cookie_val=crypt($uname[$user_id]);
  79. //set the cookie so it dies when the browser is closed
  80. setcookie ("name", $known_as[$user_id], 0);
  81. setcookie ("this_cookie", $cookie_val, 0);
  82. header("Location: $success_page");
  83. exit();
  84. }
  85.  
  86. //if a user tries to access validate.php directly and they are logged in
  87. if($REQUEST_URI == $validate_path){
  88. echo "<html>\n<head>\n";
  89. echo "<title>Yor are logged in</title>\n";
  90. echo "</head>\n";
  91. echo "<body bgcolor=\"white\">\n";
  92. echo "You are logged in. <a href=\"".$success_page."\">Continue</a>\n";
  93. echo "</body>\n";
  94. echo "</html>\n";
  95.  
  96. }
  97.  
  98. ?>

Index
  1. <html>
  2. <head>
  3. <title>Login Page</title>
  4. </head>
  5. <body bgcolor="white">
  6. <table width="400" align="center">
  7. <tr>
  8. <th valign=top> private area </th>
  9. </tr>
  10. <tr>
  11. <td>
  12. <p>This is a private area. </p>
  13. <p>Please log in below if you have access to this area </p>
  14. <?
  15. //if no cookie is set then display the form
  16. if(!isset($_COOKIE["this_cookie"])){
  17. echo '<div align="center"><form action="validate.php" method="post">';
  18. echo 'username : <input type="text" name="username"><br><br>';
  19. echo 'password : <input type="password" name="password"><br><br>';
  20. echo '<input type="submit" value="login"></form></div>';
  21. }else{
  22. echo "You are already logged in. <a href=\"addmembers.php\">Continue</a>";
  23. }
  24. ?>
  25. </td>
  26. </tr>
  27. </table>
  28. </body>
  29. </html>

Addmembers.php
  1. <?
  2. include("validate.php");
  3. ?>
  4. <?php
  5. if(mysql_connect("sql.wyger", "db_Intensity", "*******"))
  6. {
  7. mysql_select_db("db_Intensity") or die(mysql_error());
  8. }
  9. else
  10. {
  11. echo 'Kan geen verbinding maken';
  12. exit;
  13. }
  14.  
  15.  
  16. if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST))
  17. {
  18. $aFouten = array();
  19. if($_POST['nick'] == '')
  20. {
  21. $aFouten[] = 'Je hebt geen nicknaam ingevuld';
  22. }
  23. if($_POST['rang'] == '')
  24. {
  25. $aFouten[] = 'Je hebt geen rang ingevuld';
  26. }
  27. if($_POST['xfire'] == '')
  28. {
  29. $aFouten[] = 'Je hebt geen xfire account ingevuld';
  30. }
  31.  
  32. if(count($aFouten) != 0)
  33. {
  34. echo 'De volgende fouten zijn opgetreden: <br /><br />';
  35. for($Fi = 0; $Fi < count($aFouten); $Fi++)
  36. {
  37. echo $aFouten[$Fi].'<br />';
  38. }
  39. echo '<br />Klik <a href="javascript:history.go(-1);">hier</a> om terug te keren';
  40. }
  41. else
  42. {
  43. mysql_query("INSERT INTO leden (nick,rang,xfire) VALUES ('".addslashes($_POST['nick'])."','".addslashes($_POST['rang'])."','".$_POST['xfire']."')") or die (mysql_error());
  44.  
  45. echo 'De gegevens zijn succesvol opgeslagen in de database';
  46. }
  47.  
  48. }
  49. else
  50. {
  51. ?>
  52. <form action=" <?=$_SERVER['PHP_SELF']?> " method="POST">
  53. Nicknaam: <input type="text" name="nick"><br />
  54. Rang: <input type="text" name="rang"><br />
  55. Xfire: <input type="text" name="xfire"><br />
  56. <input type="submit" name="verzenden" value="verzenden">
  57. </form>
  58. <?
  59. }
  60. ?>
  61. [<a href="logout.php">Log Out</a>]


Maar nu log ik niet in :S.Als het passwoord verkeerd is krijg ik wel een melding.Anders gewoon dezelfde pagina.

Voorbeeld:
http://www.intensity.be.tt/V2.0/admin/

3 antwoorden

Gesponsorde links
Offline haytjes - 07/02/2006 20:57
Avatar van haytjes Gouden medailleGouden medaille

JS gevorderde
ik kan wel inloggen met
Citaat:
user: finduilas
pass: test


kijkt dus een keer naar je browser of je cookies accepteert
Offline finduilas - 07/02/2006 21:01
Avatar van finduilas PHP gevorderde Hoe doe je dat?

Ik heb ze even allemaal verwijderd.Maar waar kun je ze accepteren en dus ook niet accepteren?
Offline haytjes - 07/02/2006 21:24
Avatar van haytjes Gouden medailleGouden medaille

JS gevorderde
heb je IE? of FF?

http://www.microsoft.com/info/cookies.mspx
http://www.mozb...ml#cookies
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.218s