看起来,在将处理表单张贴到它的头上,然后在重新加载时,源格式化中断,因为css div消失了,会话无法工作。
<?php session_start(); ?>
<html>
<head>
<title>Webpage</title>
<link rel="stylesheet" type="text/css" href="Style.css">
</head>
<body>
<Div align="center">
<Formlad>
<form action="loginprocess.php" method="post" target="_self">
Username: <input type="text" name="username" Value='' required><BR>
Password: <input type="password" name="pass" Value='' required><BR>
Submit: <input type="submit" value="Submit" required>
</form>
</Formlad>
</Div>
<div align="center">
<Errorbox>
<?php
echo ($_SESSION['Logindets']);
?>
</Errorbox>
</div>
</body>
</html>好的,数据被发布到处理页面,然后设置会话,一个标题将用户带回页面,并给出关于登录成功的消息。这是一份测试文件,hense是一次成功尝试的不合逻辑的重定向。
<html>
<?php
$tmpusername=$_POST["username"];
$tmppassword=htmlspecialchars($_POST["pass"]);
$con=mysqli_connect("localhost","usr","password","database") or die(mysql_error());
$pnquery = "SELECT max(ID) AS ID from table" ;
$result = mysqli_query($con,$pnquery);
$IDtemp=(mysqli_fetch_array($result));
$IDmax=$IDtemp['ID'];
$IDc=1;
While ($IDc<>($IDmax+1)){
$pnquery = "SELECT Username from table Where ID ='$IDc'" ;
$result = mysqli_query($con,$pnquery);
$Usrtemp=(mysqli_fetch_array($result));
if ($tmpusername==$Usrtemp['Username']){
$nothiredu=1;
}
$IDc=$IDc+1;
}
$IDc=1;
While ($IDc<>($IDmax+1)){
$pnquery = "SELECT Password from table Where ID ='$IDc'" ;
$result = mysqli_query($con,$pnquery);
$Usrtemp=(mysqli_fetch_array($result));
if ($tmppassword==$Usrtemp['Password']){
$nothiredp=1;
}
$IDc=$IDc+1;
}
$IDc=1;
While ($IDc<>($IDmax+1)){
$pnquery = "SELECT Username from table Where ID ='$IDc'" ;
$result = mysqli_query($con,$pnquery);
$Usrtemp=(mysqli_fetch_array($result));
if ($tmpusername==$Usrtemp['Username']){
$hiredu=1;
}
$IDc=$IDc+1;
}
$IDc=1;
While ($IDc<>($IDmax+1)){
$pnquery = "SELECT Password from table Where ID ='$IDc'" ;
$result = mysqli_query($con,$pnquery);
$Usrtemp=(mysqli_fetch_array($result));
if ($tmppassword==$Usrtemp['Password']){
$hiredp=1;
}
$IDc=$IDc+1;
}
If (($nothiredu==1) and ($nothiredp==1)){
$_SESSION['Logindets']='STUFfff.......';
header("Location: http://localhost/Login.php");
exit;
}
if (($hiredu==1) and ($hiredp==1)){
$pnquery = "SELECT ID from table Where Username ='$tmpusername'" ;
$result = mysqli_query($con,$pnquery);
$IDtemp=(mysqli_fetch_array($result));
$_SESSION['Logindets']='YOUR IN SON WHOOOP';
$_SESSION['Loginsuc']=1;
$_SESSION['LoginTime'] = time();
$_SESSION['LoginID'] = $IDtemp['ID'];
$_SESSION['LoginUsr'] = $tmpusername;
header("Location: http://localhost/Login.php");
// put this ------ if($_SESSION['loginTime'] + 1000 < time()){ ------ on each page where the login is being used.
}
if (($hiredu==1) and ($hiredp==0)){
//Username is correct incorrect password
$_SESSION['Logindets']='Your Username or Password is incorrect';
header("Location: http://localhost/Login.php");
exit;
}
if ($hiredu==0){
$_SESSION['Logindets']='Your Username or Password is incorrect';
header("Location: http://localhost/Login.php");
}
?>
</html>所以我的问题不再是我的表单有什么问题,而是我的php有什么问题?
发布于 2014-04-10 16:10:32
使用两个标头总是会出现一些错误,尝试在上面的代码中使用die()代替exit()
或
使用元标签
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://localhost/Login.php">https://stackoverflow.com/questions/22992613
复制相似问题