Skip to content

Instantly share code, notes, and snippets.

@fddcddhdd
Created October 1, 2013 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fddcddhdd/6774618 to your computer and use it in GitHub Desktop.
Save fddcddhdd/6774618 to your computer and use it in GitHub Desktop.
PHPでCAPTCHA実装
<?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