Código PHP:
<?php // PHP code on the server where the form is submitted to
session_start();
// Sample PHP code
?>
<html>
<head>
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="http://localhost/kidon/js/jquery.simpleCaptcha-0.2.min.js"></script>
<script type="text/javascript" src="http://localhost/kidon/js/jquery.simpleCaptcha-0.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#captcha1').simpleCaptcha();
});
</script>
</head>
<body>
<form method='POST' action="verifica.php">
<div id='captcha1'></div>
<input type='submit'/>
</form>
</body>
</html>
Código PHP:
<?php // PHP code on the server where the form is submitted to
session_start();
// Sample PHP code
// This is the PHP code you need to use on form submission to see if the user got the
// captcha right. Note that this is for "POST" requests, and you may need to alter the
// code to suit your needs.
if (isset($_SESSION['simpleCaptchaAnswer']) && $_POST['captchaSelection'] == $_SESSION['simpleCaptchaAnswer']) {
echo"si sirve";
}
else{ echo"no sirver"; };
?>
Código PHP:
<?php
// This is the handler for captcha image requests
// The captcha ID is placed in the session, so session vars are required for this plug-in
session_start();
// -------------------- EDIT THESE ----------------- //
$images = array(
'casa'=> 'captchaImages/01.png',
'llave'=> 'captchaImages/04.png',
'bandera'=> 'captchaImages/06.png',
'reloj'=> 'captchaImages/15.png',
'bicho'=> 'captchaImages/16.png',
'lapiz'=> 'captchaImages/19.png',
'bombilla'=> 'captchaImages/21.png',
'nota musical'=> 'captchaImages/40.png',
'corazon'=> 'captchaImages/43.png',
'mundo'=> 'captchaImages/99.png'
);
// ------------------- STOP EDITING ---------------- //
$_SESSION['simpleCaptchaAnswer'] = null;
$_SESSION['simpleCaptchaTimestamp'] = time();
$SALT = "o^Gj".$_SESSION['simpleCaptchaTimestamp']."7%8W";
$resp = array();
header("Content-Type: application/json");
if (!isset($images) || !is_array($images) || sizeof($images) < 3) {
$resp['error'] = "There aren\'t enough images!";
echo json_encode($resp);
exit;
}
if (isset($_POST['numImages']) && strlen($_POST['numImages']) > 0) {
$numImages = intval($_POST['numImages']);
} else if (isset($_GET['numImages']) && strlen($_GET['numImages']) > 0) {
$numImages = intval($_GET['numImages']);
}
$numImages = ($numImages > 0)?$numImages:5;
$size = sizeof($images);
$num = min(array($size, $numImages));
$keys = array_keys($images);
$used = array();
mt_srand(((float) microtime() * 587) / 33);
for ($i=0; $i<$num; ++$i) {
$r = rand(0, $size-1);
while (array_search($keys[$r], $used) !== false) {
$r = rand(0, $size-1);
}
array_push($used, $keys[$r]);
}
$selectText = $used[rand(0, $num-1)];
$_SESSION['simpleCaptchaAnswer'] = sha1($selectText . $SALT);
$resp['text'] = ''.$selectText;
$resp['images'] = array();
shuffle($used);
for ($i=0; $i<sizeof($used); ++$i) {
array_push($resp['images'], array(
'hash'=>sha1($used[$i] . $SALT),
'file'=>$images[$used[$i]]
));
}
echo json_encode($resp);
exit;
?>