文件代碼分享
//form.php
<?php
error_reporting(E_ALL & ~E_NOTICE);
//判斷是否存在authorcode
if(isset($_REQUEST['authorcode'])){
? ? session_start();
? ? if(strtolower($_REQUEST['authorcode'])==$_SESSION['authorcode']){
? ? ? ? echo '<script>alert("輸入成功");</script>';
? ? }else{
? ? ? ? echo '<script>alert("輸入錯誤");</script>';
? ? }
}
?>
<!DOCTYPE html>
<html>
<head>
? ? <meta charset="utf-8">
? ? <title>表單驗證</title>
? ? <script>
function change(){
//alert("sdd");
document.getElementById("captcha").src="captcha.php?/res="+Math.random();
}
? ? </script>
</head>
<body>
<form action="form.php" method="post">
? ? <h3>表單驗證</h3>
? ? <p>驗證碼圖片:<img id="captcha" src="captcha.php?res=<?php echo rand();?>">
? ? <a href="javascript:void(0)" onclick='change()'>換一個?</a>
? ? </p>
? ? <p>請輸入驗證碼:<input type="text" name="authorcode" placeholder="請輸入驗證碼中內容" value="">
? ? </p>
? ? <p><input type="submit" value="確定"></p>
</form>
</body>
</html>