-
-
Save ryoakg/e0c49bcf79c12c1f43cacf99369ea8c9 to your computer and use it in GitHub Desktop.
PHPでCAPTCHA実装
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (PHP_SAPI === 'cli') { | |
echo 'Usage:' . PHP_EOL; | |
echo ' Download Securimage archive from http://www.phpcaptcha.org/download/ and decompress.' . PHP_EOL; | |
echo ' run: php -S localhost:8080' . PHP_EOL; | |
echo " browse: http://localhost:8080/{$argv[0]}" . PHP_EOL; | |
exit; | |
} | |
session_start(); | |
if(isset($_POST['captcha_code'])){ | |
require_once("./securimage/securimage.php"); | |
$securimage = new Securimage(); | |
if ($securimage->check($_POST['captcha_code']) == false) { | |
echo "認証失敗!"; | |
exit; | |
} else { | |
header('Location: http://www.google.co.jp') ; | |
} | |
} | |
?> | |
<html> | |
<head> | |
<title>secureimage catpcha test</title> | |
<script> | |
function alter_image(){ | |
document.getElementById('captcha').src = './securimage/securimage_show.php?' + Math.random(); | |
} | |
</script> | |
</head> | |
<body> | |
<div> | |
<form action="" method="post"> | |
<img id="captcha" src="./securimage/securimage_show.php" alt="CAPTCHA Image" /><br /> | |
<input type="text" name="captcha_code" size="10" maxlength="6" /> | |
<a href="#" onclick="alter_image()"> | |
<img src="./securimage/images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/> | |
</a> | |
<input type="submit" value="check"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment