Simple código para poner un captcha en tu web, muy sencillo rápido y no requiere de fuentes o imágenes.
En el código solo hace sumas y de número del 1 al 5.
También “encripta” el resultado visual para que sea un poco más difícil para los bots reventar el captcha.
Todo esto lo puedes cambiar.
function mathCaptcha(){
$first_number=mt_rand(1, 5);//first operation number
$second_number=mt_rand(1, 5);//second operation number
$_SESSION["mathCaptcha"]=($first_number+$second_number);//operation result
$operation=" ".encode_str($first_number ." + ". $second_number)."?";//operation codifieds
echo T_HOW_MUCH.$operation;
}
function encode_str ($input)//converts the input into Ascii HTML, to ofuscate a bit
{
for ($i = 0; $i < strlen($input); $i++) {
$output .= "&#".ord($input[$i]).';';
}
//$output = htmlspecialchars($output);//uncomment to escape special chars
return $output;
}Uso:
if($_POST["math"] == $_SESSION["mathCaptcha"]) {
}
< ? mathCaptcha();?>;
< in put id="math" maxlength="2" name="math" size="2" type="text" />Mas sencillo no se puede ;)
Recomendados:
