我在页面上有一个表单,该表单重定向到该人必须登录的页面。一旦他们的登录被验证,它将它们返回到表单以填写信息。我希望他们在授权页面上放置的用户名位于表单上的隐藏字段中,但它不传递变量。我认为它是认证过程中的一部分。
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['snumber'])) {
$loginUsername=$_POST['snumber'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "xxx.php";
$MM_redirectLoginFailed = "sorry.html";
$MM_redirecttoReferrer = false;
mysql_select_db($database_name, $name);
$LoginRS__query=sprintf("SELECT snumber, password FROM stverification WHERE snumber=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $pease2) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
form code:
<input type="hidden" name="snumber" value="<?php echo $_POST['snumber']; ?>">
答案 0 :(得分:1)
因为您在会话中设置了用户名,所以您也可以在重定向表单上使用它,如下所示:
表单代码:
<input type="hidden" name="snumber" value="<?php echo $_SESSION['MM_Username']; ?>">