我如何在我的脚本中的chk_Btn_Sub()中使用此函数,我哪里出错?
<?php
//start my session
session_start();
//calling the function
chk_Btn_Sub();
?>
//displays my form
<form method="post" action="captcha.php">
<table border="0" cellspacing="3" cellpadding="3">
<tr><td>Type The Letters You See Below Into the Box</td></tr>
<tr><td align="center"><img src="image.php"></td></tr>
<tr><td align="center"><input type="text" name="image" value="">
//check if the $error = true
<?php if (isset($error)): ?>
<div style="color:red;">error</div>
<?php else: ?>
<?php if (isset($success)):?>
<div style="color:green;">success</div>
<?php endif ?>
<?php endif ?>
</td></tr>
<tr><td align="center"><input type="submit" name="submit" value="Check CAPTCHA"> </td></tr>
</table>
</form>
这是我正在创建的函数,在session_start()函数下的页面顶部调用
<?php
function chk_Btn_Sub(){
if (isset($_POST["submit"])) {
if (empty($_POST["image"]) || isset($_POST['image']) != $_SESSION['string']){
$error = true;
}else{
$success = true;
}
}
return false;
}
?>
答案 0 :(得分:0)
您正在正确调用该函数,但您需要记住include
该函数所在的文件,然后才能使用它。例如
<?php
//start my session
session_start();
//include the file
include 'path/to/file.php';
//calling the function
chk_Btn_Sub();
?>