似乎在处理表单发布到它之后会转到标题,然后重新加载源格式化会在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 notogical redirect of一次成功的尝试。
<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出了什么问题?
答案 0 :(得分:0)
使用两个标头总是会出现一些错误,请尝试在上面的代码中使用die()而不是exit()
OR
使用元标记
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://localhost/Login.php">