gpt4 book ai didi

php - 提交时登录表单重定向回自身

转载 作者:行者123 更新时间:2023-11-29 06:10:31 27 4
gpt4 key购买 nike

我有一个登录表单,提交后;重定向回登录页面。我似乎找不到任何语法错误,所以我想我一定真的错过了对登录表单至关重要的东西。这是代码。

登录.php:

<?
require ('../includes/config.inc.php');
if ($_POST['act'] == "Insert") {
#// Additional security check
$RR = mysql_query("SELECT id from BPLA_adminusers");
if (mysql_num_rows($RR) > 0) {
print "Fatal error: user cannot be inserted - one or more administrators are already present in the database.<a href=login.php>login page</a>";
exit ;
}
$md5_pass = md5($MD5_PREFIX . $_POST['password']);
echo $query = "insert into BPLA_adminusers values (10,'$_POST[username]', '$md5_pass', '20011224', '20020110093458', 1)";
$result = @mysql_query($query);
#// Redirect
Header("Location: login.php");
exit ;
}
$query = "select MAX(id) from BPLA_adminusers";
$result = @mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$id = $row[0] + 1;
}
?>
<?
if($id==1) {
$id=0;
?>
<form name="login" data-ajax="false" action="login.php" method="post">
<span><? print $ERR;?></span>
<label for="<? print "Username";?>"><? print "Username";?></label>
<input type="text" name="username" />
<label for="<? print "Password";?>"><? print "Password";?></label>
<input type="password" name="password" />
<input type="submit" name="action" value="<? echo $MSG_5204;?>">
</form>
<?
} else {
$id=1;
#//
if($_POST[action] == "login") {
if(strlen($_POST[username]) == 0 || strlen($_POST[password]) == 0) {
$ERR = $ERR_047;
} else {
$query = "select * from BPLA_adminusers where username='$_POST[username]' and password='".md5($MD5_PREFIX.$_POST[password])."'";
$res = @mysql_query($query);
if(!$res) {
print "Error: $query<BR>".mysql_error();
exit;
}
if(mysql_num_rows($res) == 0) {
$ERR = $ERR_048;
} else {
$admin = mysql_fetch_array($res);
#// Set sessions vars
$BPLowbidAuction_ADMIN_LOGIN = $admin[id];
$BPLowbidAuction_ADMIN_USER = $admin[username];
$_SESSION["BPLowbidAuction_ADMIN_LOGIN"]=$BPLowbidAuction_ADMIN_LOGIN;
$_SESSION["BPLowbidAuction_ADMIN_USER"]=$BPLowbidAuction_ADMIN_USER;
#// Update last login information for this user
$query = "update BPLA_adminusers set lastlogin='".date("YmdHis")."' where username='$admin[username]'";
$rr = mysql_query($query);
if(!$rr) {
print "Error: $query<BR>".mysql_error();
exit;
}
#// Redirect
print "<SCRIPT Language=Javascript>
parent.location.href='index.php';
</SCRIPT>";
//Header("Location: home.php");
exit;
}
}
}
?>
<? if(!$act || ($act && $ERR)) {
?>
<form name="login" data-ajax="false" action="login.php" method="post">
<span><? print $ERR;?></span>
<label for="<? print "Username";?>"><? print "Username";?></label>
<input type="text" name=username />
<label for="<? print "Password";?>"><? print "Password";?></label>
<INPUT TYPE=password name=password />
<input type="submit" NAME="action" VALUE="login">
</form>
<? }?>
<? }
require("./footer.php");
?>

此代码被放置在index.php中,并在if/else语句中使用,以便在提交时再次重定向到index.php。

index.php:

<?
require ('../includes/config.inc.php');
include ('bar.php');
if (!empty($_SESSION['BPLowbidAuction_ADMIN_LOGIN'])) {
include ('home.installation.php');
} else {
include ('login.php');
}
?>

问题是登录表单首先重定向到“login.php”,然后返回“index.php”,其中显示登录表单代码,就好像我从未登录过一样。“bar.php”只是标题页面的菜单和“home.installation.php”只是实际应该显示的主页。

最佳答案

Header("Location: login.php");

Location header 必须指向绝对且有效的 URI。 IE。应以架构 (http://) 或正斜杠 /login.php

开头

HTTP 1.1 RFC on Location

关于php - 提交时登录表单重定向回自身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9386301/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com