- Ariën -
27-07-2020 16:51
gewijzigd op 27-07-2020 16:53
Ik gebruik een eenvoudige rekensom.
<?php
$_SESSION['num1'] = rand(1,9);
$_SESSION['num2'] = rand(1,9);
$_SESSION['numsum'] = $_SESSION['num1'] * $_SESSION['num2'];
?>
Dan in een HTML FORM :
<label for="human"><?php echo $_SESSION['num1'] . ' * ' . $_SESSION['num2'] . ' = ?' ;?></label>
<input
type="number"
id="human"
name="human"
size="3"
placeholder="Uw antwoord"
/>
<?php echo $text['errHuman'] <> '' ? '<br />' . $text['errHuman'] : ''; ?>
</div>
Na versturen :
<?php
if ( isset( $_POST['submit'] ) )
{
//Check if simple anti-bot test is correct
$human = intval($_POST['human']);
if ( $human != $_SESSION['numsum'] )
{
$text['errHuman'] = 'Uw anti-spam is onjuist';
}
}
?>
Dit is zo makkelijk dat ook mensen op CITO toets nivo kunnen antwoorden.
[size=xsmall]
Toevoeging op 27/07/2020 17:52:53:[/size]
En als je toch mensen op de proef wilt stellen :
<?php
session_start();
if ( isset( $_POST['a'] ) )
{
echo '<pre>' . print_r( $_POST, TRUE ) . '</pre>';
if ( in_array( md5( $_POST['a'] ), $_SESSION['captcha_ans'] ) )
{
echo '<p>Bingo</p>';
} else {
echo '<p>Onjuist</p>';
}
}
// textcaptcha.com
$url = 'http://api.textcaptcha.com/example.json';
echo '<p>' . $url . '</p>';
$captcha = json_decode( file_get_contents( $url ), TRUE );
if ( !$captcha )
{
$captcha = array( // fallback challenge
'q' => 'Is ice hot or cold?',
'a' => array( md5('cold') )
);
}
echo '<pre>' . print_r( $captcha, TRUE ) . '</pre>';
// store answers in session
$_SESSION['captcha_ans'] = $captcha['a'];
echo '<pre>' . print_r( $_SESSION, TRUE ) . '</pre>';
?>
<form method="POST" action="">
Vraag : <?php echo htmlentities( $captcha['q'] ); ?> <input type="text" name="a" value="" /><br />
<input type="submit" name="submit" value="Antwoord" />
</form>
- Ariën - op 27/07/2020 16:51:42
(Offtopic: En waarom maakt die gast een repository aan per bestand?)
Dat zijn
gists en die zijn onder andere bedoeld om
snippets code te delen.
Dank, ik ga kijken of ik hier uit kom.
Hopelijk wel, en anders horen we wel waar je op vastloopt.