login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Beveiliging > beveiliging met verificatie code

beveiliging met verificatie code

Auteur: Stijn1 - 27 september 2004 - 19:34 - Gekeurd door: Dennisvb - Hits: 17287 - Aantal punten: 4.14 (11 stemmen)





Zo hier is het dan, het scriptje voor wat extra beveiliging

Code:
-- form.php --
  1. <?PHP
  2. function form_val($url, $chars = false, $this_chars = false){
  3. if($chars == false || !is_numeric($chars)){
  4. $chars = 6;
  5. }
  6. if($this_chars == false || !is_array($this_chars)){
  7. $this_chars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  8. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  9. '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
  10. );
  11. }
  12. if($chars == false || !is_numeric($chars)){
  13. $chars = 6;
  14. }
  15. if(empty($_SESSION['validate_code'])){
  16. $save = '';
  17. for($for = 0; $for < $chars; $for++){
  18. $save .= $this_chars[mt_rand(0, (count($this_chars)-1))];
  19. }
  20. $_SESSION['validate_code'] = $save;
  21. }
  22. $ret = '<table border="0" cellpadding="3" cellspacing="0">
  23. <form method="POST">
  24. <tr>
  25. <td><img src="validate.php" /></td>
  26. </tr>
  27. <tr>
  28. <td><input type="text" name="val"></td>
  29. </tr>
  30. <tr>
  31. <td><input type="submit" name="valid" value="Validate"></td>
  32. </tr>
  33. </form>
  34. </table>';
  35. if(isset($_POST['valid'])){
  36. if($_POST['val'] == $_SESSION['validate_code']){
  37. $_SESSION['validate_code'] = '';
  38. header('Location: '.$url);
  39. }
  40. else{
  41. $ret .= 'De code klopt niet!';
  42.  
  43. }
  44. }
  45. return $ret;
  46.  
  47. }
  48. if($_GET['act'] == 'Yep'){
  49. echo 'Goed zo!';
  50. }
  51. else{
  52. echo form_val('?act=Yep');
  53. }
  54. ?>


-- validate.php --
  1. <?PHP
  2. function validate(){
  3. $save = $_SESSION['validate_code'];
  4. $width = strlen($save)*15;
  5. $height = 30;
  6. header("Content-type: image/png");
  7. $image = imagecreate($width, $height);
  8. $bgcol = imagecolorallocate($image, 255, 255, 255); // = white
  9. $licol = imagecolorallocate($image, 128, 128, 128); // = gray
  10. $tecol = imagecolorallocate($image, 0, 0, 0); // = black
  11. imageline($image, 0, 0, $width, 0, $licol);
  12. imageline($image, 0, 5, $width, 5, $licol);
  13. imageline($image, 0, 10, $width, 10, $licol);
  14. imageline($image, 0, 15, $width, 15, $licol);
  15. imageline($image, 0, 20, $width, 20, $licol);
  16. imageline($image, 0, 25, $width, 25, $licol);
  17. imageline($image, 0, 29, $width, 29, $licol);
  18. imageline($image, ($width-1), 0, ($width-1), $height, $licol);
  19. for($for3 = 0; $for3 < $width; $for3++){
  20. if($for3%5 == 0){
  21. imageline($image, $for3, 0, $for3, $height, $licol);
  22. }
  23. }
  24. for($for2 = 0; $for2 < strlen($save); $for2++){
  25. imagestring($image, 5, (2+($for2*15)), (mt_rand(2, 15)), $save{$for2}, $tecol);
  26. }
  27. return imagepng($image);
  28. imagedestroy($image);
  29. }
  30. echo validate();
  31. ?>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (15)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.036s