Php 如何为我自己的联系人表单添加自己的验证码
我正在使用dreamweaver cc创建一个表单。表单是用php编写的,运行良好。现在我想为验证方法添加验证码图像或文本。如何使用我的代码添加验证码 我的表格看起来像这样Php 如何为我自己的联系人表单添加自己的验证码,php,forms,dreamweaver,Php,Forms,Dreamweaver,我正在使用dreamweaver cc创建一个表单。表单是用php编写的,运行良好。现在我想为验证方法添加验证码图像或文本。如何使用我的代码添加验证码 我的表格看起来像这样 <table width="100%" border="1" align="center" cellpadding="2"> <form method="post" action="contact_process.php"><tr> <td><input type="te
<table width="100%" border="1" align="center" cellpadding="2">
<form method="post" action="contact_process.php"><tr>
<td><input type="text" name="name" placeholder="Enter Name" class="add_input_data" required/></td>
</tr>
<tr>
<td><input type="text" name="mobile" placeholder="Enter Mobile" class="add_input_data" required/></td>
</tr>
<tr>
<td><select name="location" class="add_input_data">
<option selected disabled>Location</option>
<option value="chittore">Chittore</option>
<option value="koduru">Koduru</option>
<option value="other">Other</option>
</select></td>
</tr>
<tr>
<td><textarea name="address" class="add_input_textarea" placeholder="Enter Address" required></textarea></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit" class="add_input_submit" align="right"/></td>
</tr></form>
</table>
位置
奇托尔
科杜鲁
其他
我的表单处理脚本如下所示
<?php
$name = $_POST['name'];
$mobile = $_POST['mobile'];
$location = $_POST['location'];
$address = $_POST['address'];
$formcontent="From: $name \n Mobile : $mobile \n Location: $location \n Address : $address";
$recipient = "dovariramu@gmail.com";
$subject = "New Connection Query";
mail($recipient, $subject, $formcontent) or die("Error!");
header('Location: thankyou.php');
?>
还有我的thankyou.php页面和一些内容。这里我不展示
现在我有两个问题
1) 当用户填写数据并单击submit按钮时,表单将显示来自thankyou.php的Successfull消息。但我想在页面中显示success full message(使用简单的滚动success full message)。
2) 我想为此表单添加验证码。如何做到这一点?对于您使用的验证码,
rand()
方法如下:
<?php
$a = rand(1,9);
$b = rand(1,9);
$c = $a + $b;
?>
在html中,编写
<h5> What is <?php echo $a; ?> + <?php echo $b; ?> ? </h5>
<input type="text" name="txt_value" id="txt_value" />
什么是+?
现在,您可以在jquery或表单提交中匹配这两个值($c和$(“#txt_value”).val())
,只要您觉得方便就可以了
希望它能帮助…验证码教程。这解决了我的问题
为了简化此过程,请使用以下php代码
function randomPassword() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
echo $pwd=randomPassword();
函数随机密码(){
$alphabet=“abcdefghijklmnopqrstuwxyzabcdefghijklmnopqrstuwxyzo123456789”;
$pass=array();//记住将$pass声明为数组
$alphaLength=strlen($alphabet)-1;//将长度-1放入缓存
对于($i=0;$i<8;$i++){
$n=兰特(0,$alphaLength);
$pass[]=$alphabet[$n];
}
return introde($pass);//将数组转换为字符串
}
echo$pwd=randomPassword();
添加验证码的最简单方法是使用谷歌的新产品。它使用起来很简单,您只需要在注册并获得站点密钥和密码。我在我的网站上使用它,效果很好。注册后,您必须添加一个简单的div元素,您希望在其中显示验证码。以及一个简单的代码来实现它,您可以找到。其100%的工作尝试它,复制div标签和过去的html,并遵循代码
<div style="padding: 1%" align="left">
<img src="captcha.php" height="20" width="81" /> <input style="height: 35px;width:235px;border-radius: 5px" type="number" name="CODE" ></br></br></div>
if(isset($_POST['LOGIN'])) {
if(empty($_POST['EMAIL']) || empty($_POST['PASSWORD'])||empty($_POST['CODE']))
{echo "<script>alert('Insert all Filds'); location ='login.php';</script>";
}
else
{
session_start();
$EMAIL = $_POST['EMAIL'];
$PASSWORD = $_POST['PASSWORD']; //echo $EMAIL . $PASSWORD;die();
$CAPTCHA = $_POST['CODE'];
$C = $_SESSION['x']; //SESSION ['X'] is define in captcha file so we compaire it with captcha below
if($CAPTCHA != $C) {
echo "<script>dialog('Invelid Captcha Code'); location ='login.php';</script>";session_destroy();}
else{
$sql = "SELECT * FROM register WHERE EMAIL = '$EMAIL' AND PASSWORD = '$PASSWORD' ";
$result = mysqli_query($conn,$sql);}
工作顺利。。。但当我输入错误的验证码时,这是一个过程。如何解决?在提交按钮上使用jquery验证码,并在表单中使用peventDefault()。
session_start();
header('content-type:image/jpeg');
$mj = $_SESSION['x'] = mt_rand(1111,9999);
$image = imagecreate(100, 50);
imagecolorallocate($image, 215, 215, 215);
$txtcolor = imagecolorallocate($image, 0, 0, 0);
imagettftext($image,20,0,20,40,$txtcolor,'font.ttf',$mj);
imagejpeg($image);