我开发了一个带有视频验证码的登录页面。现在登录功能完美无缺。
在此页面中,用户需要观看视频,然后在答案与数据库匹配后允许登录之前回答问题。
问题是如何使用数据库中的答案验证输入的答案。我的视频数据库表由ID | Video | question | answer
require "config.php"; //Connection Script, include in every file!
//Check to see if the user is logged in.
if(isset($_SESSION['email'])){
header("location: members.php"); //isset check to see if a variables has been 'set'
}
if(isset($_POST['submit']))
{
//Variables from the table
$email = $_POST['email'];
$password = $_POST['password'];
//Prevent MySQL Injections
$email = stripslashes($email);
$password = stripslashes($password);
$email = mysqli_real_escape_string($con, $email);
$password = mysqli_real_escape_string($con, $password);
//Check to see if the user left any space empty!
if($email == "" || $password == "")
{
echo "Please fill in all the information!";
}
//Check to see if the username AND password MATCHES the username AND password in the DB
else
{
$query = mysqli_query($con,"SELECT * FROM detail WHERE email = '$email' and password = '$password'") or die("Can not query DB.");
$count = mysqli_num_rows($query);
if($count == 1){
//YES WE FOUND A MATCH!
$_SESSION['email'] = $email; //Create a session for the user!
header ("location: members.php");
}
else{
echo "Username and Password DO NOT MATCH! TRY AGAIN!";
}
}
}
?>
</span>
<form action="login.php" method="post">
<label><b>Login</b>Not a member? <a href="http://localhost/captcha1/register.php"> Register </a> now!</label><br /><br />
<label>Email :<span>*</span></label><br />
<input name="email" type="text" id="email" placeholder="username@domain" required>
<br />
<label>Password :<span>*</span></label><br />
<input name="password" type="password" id="password" placeholder="********"required>
<br />
</div>
<div style="float:right; width:50%; ">
<?php
mysql_connect("localhost","root","");
mysql_select_db("details");
$res=mysql_query("select * from video ORDER BY RAND() LIMIT 1");
while($row=mysql_fetch_array($res))
{
?>
<center><video width="360" height="270" controls><source src="**<?php echo $row["video"];?>**" type="video/mp4">
</video><center>**<?php echo $row['question']; ?>**</center> </center>
<input name="captcha" type="text" size"4" placeholder="" required><br>
</fieldset>
<br /><br />
<input type="reset" value="Reset" />
<input type="submit" name="submit" value="Login">
</form>
<?php
}
?>