日志php页面不重定向
问题描述:
我有一个使用Dreamweaver CS4创建的login.php页面。 在表单中输入用户名和密码后,页面会自动重新加载而不会重定向到所需的位置。 网址现有的网站:http://www.decoraflooringstore.com 登录页面点击客户端登录 后打开下面是PHP代码: 感谢任何输入日志php页面不重定向
<?php require_once('Connections/test.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_test, $test);
$query_Recordset1 = "SELECT `user`.`user name`, `user`.password FROM `user`";
$Recordset1 = mysql_query($query_Recordset1, $test) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?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['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['username'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "success login.php";
$MM_redirectLoginFailed = "failed login.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_test, $test);
$LoginRS__query=sprintf("SELECT `user name`, password FROM `user` WHERE `user name`=%s AND password=%s",
GetSQLValueString($loginUsername, "-1"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $test) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
//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);
}
}
?>
<table width="500" border="0" align="center">
<tr>
<td><table width="400" border="0" align="center">
<tr>
<td>Username</td>
<td><form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<label>
<input type="text" name="username" id="username" />
</label>
</form></td>
</tr>
<tr>
<td>Password</td>
<td><form id="form2" name="form2" method="post" action="">
<label>
<input type="text" name="password" id="password" />
</label>
</form></td>
</tr>
<tr>
<td> </td>
<td><form id="form3" name="form3" method="post" action="">
<label>
<input type="submit" name="login" id="login" value="Login" />
</label>
</form></td>
</tr>
</table></td>
</tr>
</table>
<?php
mysql_free_result($Recordset1);
?>
答
为了能够重定向,必须避免将以前的内容。否则,您将收到消息“标题已发送”。
命令session_start()将发送标题,不允许进一步重定向。
避免也有多个打开和关闭php标签。您要在结束标记和下一个开始标记之间发送换行符。这也会导致标题被发送,不允许重定向按预期工作。
答
使用isset函数检查用户名和密码。和我在条件语句中 如果passsword正确 header(“location:index.php”); else header(“location:something.php”); 它是什么,如果你的信息是有效的,它会重定向到index.php,如果不是有效的,它将重定向到something.php
建议:你不需要打开和关闭一个php标签每个功能哟有这是NASTY) – 2013-10-04 02:18:14