我正在为自己开发一个非常简单的登录系统,不打算在线发布。我的场景:在注册期间,用户选择他的用户名并插入所需的点击次数进行登录,它将存储在数据库中。在登录期间,用户将首先输入他的用户名,然后用户将被重定向到一个页面,用户将在该页面上单击具有 onclick 功能的图像以计算点击次数。
问题:如何从 login.php 中获取“点击次数”,然后与 checkclick.php 中记录的点击次数进行比较?我已经尽力找到自己的想法来做这几天了。然而,我失败了。老实说,我编程很慢而且很弱,所以我希望我能在这里得到一些帮助。我的朋友确实建议我使用 AJAX,但是看完教程后,我真的不明白。有人可以帮忙吗?我会很感激。
非常感谢您阅读并帮助解决我的问题。
login.php
<?php
include("connection.php");
$username = $_SESSION["CID"];
$table1=mysql_query("select * from pic_a");
$table2=mysql_query("select * from pic_b");
$table3=mysql_query("select * from pic_c");
$tab1[0]=0;
$tab2[0]=0;
$tab3[0]=0;
$i=0;
while($row=mysql_fetch_assoc($table1))
{
$tab1[$i]= $row["pic_link"];
$i++;
}
$i=0;
while($row=mysql_fetch_assoc($table2))
{
$tab2[$i]= $row["pic_link"];
$i++;
}
$i=0;
while($row=mysql_fetch_assoc($table3))
{
$tab3[$i]= $row["pic_link"];
$i++;
}
$rand1=rand(0,9);
$rand2=rand(0,9);
$rand3=rand(0,9);
?>
<script type="text/javascript">
var count = 0;
function countClicks() {
count = count + 1;
document.getElementById("clicks").innerHTML = count;
}
</script>
<body>
<h1>login</h1>
<form action = "" name = "allpass" method = "post" enctype = "multipart/form-data">
<p style="font-size:20px">Username: <?php echo $username;?> </p>
<p style="font-size:20px">Password:</p>
<p><table border = 0>
<td>
<div STYLE=" height: 800px; width: 165px; font-size: 12px;">
<table border="1">
<tr id="bird" onclick="countClicks();">
<td><img src="password\<?php echo $tab1[$rand1]; ?>" alt="" width="76" height="67"></td>
<td>Bird</td>
</tr>
<tr id="car" onclick="countClicks();">
<td><img src="password\<?php echo $tab2[$rand2]; ?>" alt="" width="76" height="67"></td>
<td>Car</td>
</tr>
<tr id="computer" onclick="countClicks();">
<td><img src="password\<?php echo $tab3[$rand3]; ?>" alt="" width="76" height="67"></td>
</table>
</div>
</td>
</table>
<p id="clicks">0</p>
<input type = "submit" style=" height: 25px; width: 75px" value = "Login" name = "submitbtn" />
</form></p>
</div>
</body>
</html>
checkclicks.php
<?php
include("connection.php");
if(!isset($_GET["username"]) || !isset($_GET["clicks"]))
die("Error");
$username = $_GET["username"];
$jsClicks = $_GET["clicks"];
$phpClicks = null;
$data = mysql_query("SELECT clicks FROM customerdetails WHERE customer_username='$username'");
while($row = mysql_fetch_array($data))
{
$phpClicks = $row["clicks"];
}
if( $phpClicks == $clicks)
{
?>
<script type="text/javascript">
alert("success");
location = "welcome.php";
</script>
<?php
} else {
?>
<script type="text/javascript">
alert("fail");
location = "login.php";
</script>
<?php
}
?>