'InputCaptcha', ':html' => "", ':args' => array('value'), 'size' => 5, 'autocomplete' => 'off', 'name' => $CaptchaName, )); array_unshift($EditFunctions, 'RequireCaptcha'); function RequireCaptcha($pagename, $page, $new) { global $EnablePostCaptchaRequired, $MessagesFmt, $CaptchaRequiredFmt, $EnablePost; if (!IsEnabled($EnablePostCaptchaRequired, 0)) return; if (IsCaptcha()) return; SDV($CaptchaRequiredFmt, "
$[Must enter valid code]
"); $MessagesFmt[] = $CaptchaRequiredFmt; $EnablePost = 0; } function IsCaptcha() { global $IsCaptcha, $CaptchaName, $EnableCaptchaSession; if (isset($IsCaptcha)) return $IsCaptcha; $key = @$_POST['captchakey']; $resp = @$_POST[$CaptchaName]; $sid = session_id(); @session_start(); if ($key && $resp && @$_SESSION['captcha-challenges'][$key] == $resp) $IsCaptcha = 1; if (IsEnabled($EnableCaptchaSession, 0)) { $IsCaptcha |= @$_SESSION['iscaptcha']; @$_SESSION['iscaptcha'] = $IsCaptcha; } $IsCaptcha = (int)@$IsCaptcha; if (!$sid) session_write_close(); return $IsCaptcha; } function InputCaptcha($pagename, $type, $args) { CaptchaValue(); return Keep(InputToHTML($pagename, $type, $args, $opt)); } function CaptchaValue() { global $CaptchaKey, $CaptchaValue; if ($CaptchaKey > '' && @$_SESSION['captcha-challenges'][$CaptchaKey] == $CaptchaValue) return $CaptchaValue; $sid = session_id(); @session_start(); if ($CaptchaKey == '') $CaptchaKey = count(@$_SESSION['captcha-challenges']); $_SESSION['captcha-challenges'][$CaptchaKey] = $CaptchaValue; if (!$sid) session_write_close(); return $CaptchaValue; } function CaptchaFn($pagename) { global $CaptchaChallenge, $EnableCaptchaImage; if (@$CaptchaChallenge) return $CaptchaChallenge; if ($EnableCaptchaImage) return CaptchaImage($pagename); return CaptchaValue(); } function CaptchaImage($pagename) { global $CaptchaKey,$CaptchaImage, $CaptchaImageFmt; CaptchaValue(); $key = @$CaptchaKey; if ($key == '') return ''; @session_start(); $value = @$_SESSION['captcha-challenges'][$key]; if (!$value) return ''; $width = 60; $height = 22; $fontwidth = 10; $fontheight = 14; $img = imagecreatetruecolor($width, $height); $white = imagecolorallocate($img, 240, 240, 240); imagefilledrectangle($img, 0, 0, $width, $height, $white); imagealphablending($img, 1); imagecolortransparent($img); for($i=0; $i < 100; $i++) { $r = rand(200, 255); $g = rand(200, 255); $b = rand(200, 255); $color = imagecolorallocate($img, $r, $g, $b); imagefilledellipse($img, round(rand(0, $width)), round(rand(0, $height)), round(rand(0, $width/8)), round(rand(0, $height/4)), $color); } $vlen = strlen($value); $x = rand(2, $width/$vlen); for($i=0; $i < $vlen; $i++) { $y = rand(2, $height - $fontheight - 2); $r = rand(0, 150); $g = rand(0, 150); $b = rand(0, 150); $fg = imagecolorallocatealpha($img, $r, $g, $b, 30); $c = substr($value, $i, 1); imagechar($img, 5, $x, $y, $c, $fg); $x += rand($fontwidth + 2, ($width-$x)/($vlen-$i)); } ob_start(); imagejpeg($img); $jpgimg = ob_get_contents(); ob_end_clean(); $base64img = base64_encode($jpgimg); $imgstr = "data:image/jpg;base64,".$base64img; SDV($CaptchaImageFmt, ""); return Keep(FmtPageName($CaptchaImageFmt, $pagename)); }