Created
October 1, 2013 06:36
-
-
Save fddcddhdd/6774618 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 session_start() ?> | |
<html> | |
<head> | |
<title>secureimage test</title> | |
</head> | |
<body> | |
<div> | |
<!-- 入力フォーム --> | |
<form action="" method="post"> | |
<!-- secureimage_show.phpを呼ぶとイメージが出てくる --> | |
<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="document.getElementById('captcha').src = './securimage/securimage_show.php?' + Math.random(); return false"> | |
<img src="./securimage/images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/> | |
</a> | |
<!-- submit ボタン --> | |
<input type="submit" value="check"> | |
<p> | |
<?php | |
// 入力があった場合のみ処理する | |
if(!empty($_POST['captcha_code'])){ | |
// secureimage.phpをインクルードする | |
include_once("./securimage/securimage.php"); | |
// Securimageのオブジェクトを作成する | |
$securimage = new Securimage(); | |
// Securimageオブジェクトの持つcheckメソッドで入力が正しいかを | |
// チェックする | |
if ($securimage->check($_POST['captcha_code']) == false) { | |
echo "認証失敗!"; | |
exit; | |
} else { | |
header('Location: http://www.google.co.jp') ; | |
} | |
} | |
?> | |
</p> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment