function js_rpc($yes) { $yes = $yes ? 1 : 0; $PARAM_INPUT = CAPTCHA_PARAM_INPUT; easy_captcha_utility::js_header(); print <<<END_____JSRPC__JSRPC__JSRPC__JSRPC__JSRPC__JSRPC_____END // JS-RPC response if (1) { captcha_rpc = 0; var inf = document.getElementById("{$PARAM_INPUT}"); inf.style.borderColor = {$yes} ? "#22AA22" : "#AA2222"; } END_____JSRPC__JSRPC__JSRPC__JSRPC__JSRPC__JSRPC_____END; }
function API() { #-- load data if ($id = @$_GET[CAPTCHA_PARAM_ID]) { #-- special case if ($id == 'base.js') { easy_captcha_utility::js_base(); } else { $c = new easy_captcha($id = NULL, $ignore_expiration = 1); $expired = !$c->is_valid(); #-- JS-RPC request, check entered solution on the fly if ($test = @$_REQUEST[CAPTCHA_PARAM_INPUT]) { #-- check if ($expired) { } if (0 >= $c->ajax_tries--) { $c->log("::API", "JS-RPC", "ajax_tries exhausted ({$c->ajax_tries})"); } $ok = $c->image->solved($test) || $c->text->solved($test); #-- sendresult easy_captcha_utility::js_rpc($ok); } else { if ($expired) { $type = "image/png"; $bin = easy_captcha_utility::expired_png(); } else { $type = "image/jpeg"; $bin = $c->image->jpeg(); } header("Pragma: no-cache"); header("Cache-Control: no-cache, no-store, must-revalidate, private"); header("Expires: " . date("r")); header("Content-Length: " . strlen($bin)); header("Content-Type: {$type}"); print $bin; } } exit; } }