[英]Logging in with wrong username and password as well
即使使用错误的用户名和密码登录,也请帮助我找出问题所在。 我希望它仅在与用户名和密码匹配时才登录,但它完全无法正常工作。
这是代码:
<form name="login" method="post" action="countries.php">
<p> </p>
<table border=0 width=500px align=center>
<tr>
<td>Enter User Name</td>
</tr>
<tr>
<td><input type=text size=30 value="" name=t1></td>
</tr>
<tr>
<td>Enter Password</td>
</tr>
<tr>
<td><input type=password size=30 value="" name=t2>
</td>
</tr>
<tr>
<td><input type=reset value="Clear Form" name=b2>
</td>
<td><input type=submit value="Login Form" name=b4>
</td>
</td></tr>
<tr>
<td><input type=submit value="Guest User" name=b5>
</td>
</tr>
</table>
<hr />
</center>
<?php
$t1="Maha";
$t2="abc";
if($t1 == "Maha" && $t2 == "abc")
{
header("countries.php");
exit;
echo " We are glad you are visiting us again. Lets plan yout tour together." ;
}
else {
header("final.php");
exit;
echo " User name or password is incorrect. Try again.";
}
?>
</form>
您还有其他一些问题,这些问题将以其他方式导致中断,但是由于您正在比较这些变量(与硬编码值),因此它总是达到登录状态:
$t1="Maha";
$t2="abc";
硬编码凭证:
if($t1 == "Maha" && $t2 == "abc")
而不是通过$_POST
读取用户输入。
您发布的形式countries.php
您的登录代码应在countries.php
另外,您在标题代码中缺少Location关键字:
header('Location: http://www.example.com/');
这里是修改后的PHP代码,应在countries.php:
<?php
$t1=$_POST['t1'];
$t2=$_POST['t2'];
if($t1 == "Maha" && $t2 == "abc")
{
header("Location: countries.php"); // probably some other page since countries.php has the login verification logic.
exit;
echo " We are glad you are visiting us again. Lets plan yout tour together." ;
}
else {
header("Location: final.php");
exit;
echo " User name or password is incorrect. Try again.";
}
?>
您的变量是通过POST传入的。
if($_POST['t1'] == "Maha" && $_POST['t2'] == "abc")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.