【发布时间】:2013-07-05 14:43:56
【问题描述】:
我有一个简单的登录页面,其中显示了用户名和密码登录部分,当按下登录按钮时,表单数据被发送回页面进行处理。如果数据有效并且他们已经成功登录,它会将他们定向到主页,如果不是,它会再次向他们显示登录屏幕并告诉他们他们做错了什么(密码错误、空白字段等)。
我的问题是,对于某些浏览器(Chrome 和 Opera),表单需要提交两次才能设置数据(字面意思是设置,我使用 isset、empty 和 is_null 检查进行了检查)。
我已经读过之前在某些浏览器(Chrome 和 IE)上存在此问题,但我发现的唯一其他解决方案是使用 javascript 来传递信息。有什么办法可以让表单更“浏览器友好”吗?
更新 1
这是表格,它是你能得到的最基础的,没什么特别的。
<form action="loginpage.php" method="POST">
Username: <input type="text" name="Username" autofocus="autofocus" />
<br/>
Password: <input type="password" name="Password" />
<br/>
<input type="submit" name="submit" />
</form>
更新 2
PHP 代码
if (isset($_POST['submit']))
{
if ($_POST['Username']=="" || $_POST['Password']=="")
{
echo '<script type="text/javascript">';
echo "window.alert('You did not fill in a required field.')";
echo "</script>";
}
else
{
$username = $_POST['Username'];
$password = $_POST['Password'];
$sql = "SELECT * FROM Logins WHERE `Username` = '$username'";
$validate = mysql_query($sql);
while ($check = mysql_fetch_array($validate))
{
if ($password != $check['Password'])
{
echo "<script type='text/javascript'>";
echo "window.alert('password was incorrect.')";
echo "</script>";
}
else
{
header("Location: streaming/videosearch.php?order=dated&q=*");
}
}
}
}
【问题讨论】:
-
Is there anything I can do to make the form more "browser friendly"?不知道 - 没有看到代码... -
可以给我们看看表单代码吗?
-
正如我所说,它很简单,但我发布了它。
-
这只是表单html,也发布
php代码。 -
您使用的是an obsolete database API,应该使用modern replacement。您还容易受到SQL injection attacks的影响,现代 API 可以让您更轻松地从 defend 中获得。