Php会话变量,阻止用户

Php会话变量,阻止用户,php,Php,嘿,谁能看看我的代码帮我。。。我正在使用apache,我正在尝试使它成为如果用户在密码和用户名中输入错误3次,它只会将它们转发到404HTML页面。不幸的是,我的一些代码显示在我的浏览器中,我不知道为什么。我对php很熟悉,所以如果代码不整洁或不正确,请不要纠缠我 login.php: <?php session_start(); $_SESSION['wrong']=0; $user = $_POST['user']; $pass = $_POST['pass']; if($user

嘿,谁能看看我的代码帮我。。。我正在使用apache,我正在尝试使它成为如果用户在密码和用户名中输入错误3次,它只会将它们转发到404HTML页面。不幸的是,我的一些代码显示在我的浏览器中,我不知道为什么。我对php很熟悉,所以如果代码不整洁或不正确,请不要纠缠我

login.php:

<?php 
session_start(); 
$_SESSION['wrong']=0;
$user = $_POST['user'];
$pass = $_POST['pass'];
if($user == "school"
&& $pass == "homework")
{
echo"Password system work!";
}else{
$_SESSION['wrong']=$_SESSION['wrong']+1;
header( 'Location: http://localhost' ) ;
}
?>
<? session_start(); 
include 'login.php';
global $_SESSION['wrong'];
if($_SESSION['wrong']>=3){
header( 'Location: 404_File_Not_Found.html' ) ; //This is what the browser is showing

}
?>
<html>
<head>
<style type="text/css">

#form{
width:  340px;
height: 400px;
box-shadow: 0px 2px 5px rgba(0,0,0,0.25);
position: relative;
-webkit-box-shadow: 0px 2px 5px;
border: solid 1px #ddd;
padding: 30px 30px 60px 30px;
background: #fff;
border-radius: 10px;
}
p{
font-family: Verdana;

}
div{
margin-left:auto;
margin-right:auto;
margin-top:5%;

}
img{
width: 120;
height: 133;
left: 100px;
position: relative;
}
input{
margin-left:10%;
margin-right:5%;
font-size: 14px;
width: 264px;
padding: 9px 7px 7px;
background: none !important;
position: relative;
z-index: 10;
margin-bottom: 20px;
border-radius: 5px;

}
.button:hover{
color: red;
}
</style>


</head>
<body>
<div id="form">     
<img src="http://traceybaptiste.files.wordpress.com/2011/01/homework2.jpg" />
    <form method="POST" action="login.php">
    <p>User:</p> <input type="text" name="user"></input>
    <p>Pass:</p> <input type="password" name="pass"></input>
    <input type="submit" name="submit" class="button"></input>
    </form>
</div>
</body>
</html>
<html>
<head>
<style>
html{
background-color:grey;
}
body{
background-image:url("404.jpg");
background-repeat:no-repeat;
margin-left: 25%;
margin-right: auto;
margin-top: 10%;

}
</style>
</head>
<body>
</body>
</html>

Index.html:

<?php 
session_start(); 
$_SESSION['wrong']=0;
$user = $_POST['user'];
$pass = $_POST['pass'];
if($user == "school"
&& $pass == "homework")
{
echo"Password system work!";
}else{
$_SESSION['wrong']=$_SESSION['wrong']+1;
header( 'Location: http://localhost' ) ;
}
?>
<? session_start(); 
include 'login.php';
global $_SESSION['wrong'];
if($_SESSION['wrong']>=3){
header( 'Location: 404_File_Not_Found.html' ) ; //This is what the browser is showing

}
?>
<html>
<head>
<style type="text/css">

#form{
width:  340px;
height: 400px;
box-shadow: 0px 2px 5px rgba(0,0,0,0.25);
position: relative;
-webkit-box-shadow: 0px 2px 5px;
border: solid 1px #ddd;
padding: 30px 30px 60px 30px;
background: #fff;
border-radius: 10px;
}
p{
font-family: Verdana;

}
div{
margin-left:auto;
margin-right:auto;
margin-top:5%;

}
img{
width: 120;
height: 133;
left: 100px;
position: relative;
}
input{
margin-left:10%;
margin-right:5%;
font-size: 14px;
width: 264px;
padding: 9px 7px 7px;
background: none !important;
position: relative;
z-index: 10;
margin-bottom: 20px;
border-radius: 5px;

}
.button:hover{
color: red;
}
</style>


</head>
<body>
<div id="form">     
<img src="http://traceybaptiste.files.wordpress.com/2011/01/homework2.jpg" />
    <form method="POST" action="login.php">
    <p>User:</p> <input type="text" name="user"></input>
    <p>Pass:</p> <input type="password" name="pass"></input>
    <input type="submit" name="submit" class="button"></input>
    </form>
</div>
</body>
</html>
<html>
<head>
<style>
html{
background-color:grey;
}
body{
background-image:url("404.jpg");
background-repeat:no-repeat;
margin-left: 25%;
margin-right: auto;
margin-top: 10%;

}
</style>
</head>
<body>
</body>
</html>

#形式{
宽度:340px;
高度:400px;
盒影:0px2p5pxRGBA(0,0,0,0.25);
位置:相对位置;
-网络工具包盒阴影:0px 2px 5px;
边框:实心1px#ddd;
填充:30px 30px 60px 30px;
背景:#fff;
边界半径:10px;
}
p{
字体系列:Verdana;
}
div{
左边距:自动;
右边距:自动;
利润率最高:5%;
}
img{
宽度:120;
身高:133;
左:100px;
位置:相对位置;
}
输入{
左边距:10%;
保证金权利:5%;
字体大小:14px;
宽度:264px;
填充:9px 7px 7px;
背景:无!重要;
位置:相对位置;
z指数:10;
边缘底部:20px;
边界半径:5px;
}
.按钮:悬停{
颜色:红色;
}
用户:

通过:

404.html:

<?php 
session_start(); 
$_SESSION['wrong']=0;
$user = $_POST['user'];
$pass = $_POST['pass'];
if($user == "school"
&& $pass == "homework")
{
echo"Password system work!";
}else{
$_SESSION['wrong']=$_SESSION['wrong']+1;
header( 'Location: http://localhost' ) ;
}
?>
<? session_start(); 
include 'login.php';
global $_SESSION['wrong'];
if($_SESSION['wrong']>=3){
header( 'Location: 404_File_Not_Found.html' ) ; //This is what the browser is showing

}
?>
<html>
<head>
<style type="text/css">

#form{
width:  340px;
height: 400px;
box-shadow: 0px 2px 5px rgba(0,0,0,0.25);
position: relative;
-webkit-box-shadow: 0px 2px 5px;
border: solid 1px #ddd;
padding: 30px 30px 60px 30px;
background: #fff;
border-radius: 10px;
}
p{
font-family: Verdana;

}
div{
margin-left:auto;
margin-right:auto;
margin-top:5%;

}
img{
width: 120;
height: 133;
left: 100px;
position: relative;
}
input{
margin-left:10%;
margin-right:5%;
font-size: 14px;
width: 264px;
padding: 9px 7px 7px;
background: none !important;
position: relative;
z-index: 10;
margin-bottom: 20px;
border-radius: 5px;

}
.button:hover{
color: red;
}
</style>


</head>
<body>
<div id="form">     
<img src="http://traceybaptiste.files.wordpress.com/2011/01/homework2.jpg" />
    <form method="POST" action="login.php">
    <p>User:</p> <input type="text" name="user"></input>
    <p>Pass:</p> <input type="password" name="pass"></input>
    <input type="submit" name="submit" class="button"></input>
    </form>
</div>
</body>
</html>
<html>
<head>
<style>
html{
background-color:grey;
}
body{
background-image:url("404.jpg");
background-repeat:no-repeat;
margin-left: 25%;
margin-right: auto;
margin-top: 10%;

}
</style>
</head>
<body>
</body>
</html>

html{
背景颜色:灰色;
}
身体{
背景图片:url(“404.jpg”);
背景重复:无重复;
左边缘:25%;
右边距:自动;
利润率最高:10%;
}


如果文件名为
index.html
,则PHP不会解析该文件


另外,使用
我不是很确定,但我认为不应该包括login.php(index.html的第二行)。我对php也有点陌生,但看起来您的表单位于index.html上,然后将数据发布到login.php,然后从那里重定向用户。在表单的开头包含login.php对我来说没有什么意义。我可能弄错了,但我只是想帮忙

我还认为William N编写的代码也是错误的,这就是为什么您被困在login.php中,如果您的密码错误,它不会将您重定向到本地主机

<?php 
session_start(); 
$_SESSION['wrong']=0;
$user = $_POST['user'];
$pass = $_POST['pass'];
if($user == "school"
&& $pass == "homework")
{
echo"Password system work!";
}else{  
$_SESSION['wrong']=$_SESSION['wrong']+1;
header( 'Location: http://localhost' ) ;}

if($_SESSION['wrong'] == 3)

header( 'Location: diepage.html' ) ;

?>

因此,只有在没有提前设置的情况下,才可以启动并将其设置为零。但我也不完全确定。

您的
index.html
不会被Apache解析为PHP。将其重命名为
index.php
。并养成在
标题(“位置…”)之后立即调用
exit()
的习惯。
谢谢你们,我将开始准确地使用它。称之为
index.php
谢谢你们的输入。我现在重命名了该文件,但当我转到login.php时,该文件仍保留在那里,它不会将我导航回本地主机。我应用了您的代码,当我输入错误的数据时,我被转发到登录,但我仍保留在那里。我希望它返回到登录页面(localhost..也称为index.html),直到它达到3,然后转发到404,最后感觉数字是3+他们无法返回index.html文件尝试登录。非常感谢。