beveiliging met verificatie code
Auteur: Stijn1 - 27 september 2004 - 19:34 - Gekeurd door: Dennisvb - Hits: 17269 - Aantal punten: 4.14 (11 stemmen)
Zo hier is het dan, het scriptje voor wat extra beveiliging
|
Code: |
-- form.php --
<?PHP
session_start();
function form_val($url, $chars = false, $this_chars = false){
if($chars == false || !is_numeric($chars)){
$chars = 6;
}
if($this_chars == false || !is_array($this_chars)){
$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',
'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',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
);
}
if($chars == false || !is_numeric($chars)){
$chars = 6;
}
if(empty($_SESSION['validate_code'])){
$save = '';
for($for = 0; $for < $chars; $for++){
$save .= $this_chars[mt_rand(0, (count($this_chars)-1))];
}
$_SESSION['validate_code'] = $save;
}
$ret = '<table border="0" cellpadding="3" cellspacing="0">
<form method="POST">
<tr>
<td><img src="validate.php" /></td>
</tr>
<tr>
<td><input type="text" name="val"></td>
</tr>
<tr>
<td><input type="submit" name="valid" value="Validate"></td>
</tr>
</form>
</table>';
if(isset($_POST['valid'])){
if($_POST['val'] == $_SESSION['validate_code']){
$_SESSION['validate_code'] = '';
header('Location: '.$url);
}
else{
$ret .= 'De code klopt niet!';
}
}
return $ret;
}
if($_GET['act'] == 'Yep'){
echo 'Goed zo!';
}
else{
echo form_val('?act=Yep');
}
?>
<?PHP function form_val($url, $chars = false, $this_chars = false){ $chars = 6; } if($this_chars == false || !is_array($this_chars)){ $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', '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', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ); } $chars = 6; } if(empty($_SESSION['validate_code'])){ $save = ''; for($for = 0; $for < $chars; $for++){ } $_SESSION['validate_code'] = $save; } $ret = '<table border="0" cellpadding="3" cellspacing="0"> <form method="POST"> <tr> <td><img src="validate.php" /></td> </tr> <tr> <td><input type="text" name="val"></td> </tr> <tr> <td><input type="submit" name="valid" value="Validate"></td> </tr> </form> </table>'; if(isset($_POST['valid'])){ if($_POST['val'] == $_SESSION['validate_code']){ $_SESSION['validate_code'] = ''; } else{ $ret .= 'De code klopt niet!'; } } return $ret; } if($_GET['act'] == 'Yep'){ } else{ echo form_val ('?act=Yep'); } ?>
-- validate.php --
<?PHP
session_start();
function validate(){
$save = $_SESSION['validate_code'];
$width = strlen($save)*15;
$height = 30;
header("Content-type: image/png");
$image = imagecreate($width, $height);
$bgcol = imagecolorallocate($image, 255, 255, 255); // = white
$licol = imagecolorallocate($image, 128, 128, 128); // = gray
$tecol = imagecolorallocate($image, 0, 0, 0); // = black
imageline($image, 0, 0, $width, 0, $licol);
imageline($image, 0, 5, $width, 5, $licol);
imageline($image, 0, 10, $width, 10, $licol);
imageline($image, 0, 15, $width, 15, $licol);
imageline($image, 0, 20, $width, 20, $licol);
imageline($image, 0, 25, $width, 25, $licol);
imageline($image, 0, 29, $width, 29, $licol);
imageline($image, ($width-1), 0, ($width-1), $height, $licol);
for($for3 = 0; $for3 < $width; $for3++){
if($for3%5 == 0){
imageline($image, $for3, 0, $for3, $height, $licol);
}
}
for($for2 = 0; $for2 < strlen($save); $for2++){
imagestring($image, 5, (2+($for2*15)), (mt_rand(2, 15)), $save{$for2}, $tecol);
}
return imagepng($image);
imagedestroy($image);
}
echo validate();
?>
<?PHP function validate(){ $save = $_SESSION['validate_code']; $height = 30; header("Content-type: image/png"); $image = imagecreate($width, $height); $bgcol = imagecolorallocate($image, 255, 255, 255); // = white $licol = imagecolorallocate($image, 128, 128, 128); // = gray $tecol = imagecolorallocate($image, 0, 0, 0); // = black imageline($image, 0, 0, $width, 0, $licol); imageline($image, 0, 5, $width, 5, $licol); imageline($image, 0, 10, $width, 10, $licol); imageline($image, 0, 15, $width, 15, $licol); imageline($image, 0, 20, $width, 20, $licol); imageline($image, 0, 25, $width, 25, $licol); imageline($image, 0, 29, $width, 29, $licol); imageline($image, ($width-1), 0, ($width-1), $height, $licol); for($for3 = 0; $for3 < $width; $for3++){ if($for3%5 == 0){ imageline($image, $for3, 0, $for3, $height, $licol); } } for($for2 = 0; $for2 < strlen($save); $for2++){ imagestring ($image, 5, (2+($for2*15)), (mt_rand(2, 15)), $save{$for2}, $tecol); } return imagepng($image); imagedestroy($image); } ?>
Download code (.txt)
|
|
Stemmen |
Niet ingelogd. |
|