限制直接页面访问
为了保护我正在处理的网站的管理员区域,我制作了一个index.php,其中包含
if (isset($_POST['password']) && isset($_POST['userName'])) {
if($_POST['password']==$pass && $_POST['userName']==$username)
{
header( 'Location: admin.php' ) ;
}
此重定向到同一文件夹中名为admin.php的文件。问题是,如果我编写localhost/folder/admin.php
,我就可以访问该文件。请告诉我如何限制对该页面的直接访问。访问它的唯一方法应该是在用户名和密码之后从index.php。
In attempt of securing an administrator area of a site I'm working on I made an index.php which contains
if (isset($_POST['password']) && isset($_POST['userName'])) {
if($_POST['password']==$pass && $_POST['userName']==$username)
{
header( 'Location: admin.php' ) ;
}
This redirects to a file in the same folder called admin.php. The problem is that I can access this file if I write localhost/folder/admin.php
. Please tell me how to restrict the direct access to this page. The only way accesing it should be from index.php after username and password.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
设置一个会话变量并在每次有人访问 admin.php 时检查
它
set a session variable and check it everytimes somebody access admin.php
and
您应该查看 PHP 会话。您可以在该重定向文件中设置会话变量“isLogged”,然后检查 admin.php 是否注册了该会话变量,如果没有注册,则重定向到登录页面!
admin.php
注意:session_start();必须在使用 $_SESSION 全局之前调用。
You should look into PHP sessions. You can set a session variable "isLogged" in that redirection file, and then check in admin.php if that session variable is registered, if not redirect to the login page!
admin.php
Note: session_start(); must be called before the $_SESSION global can be utilised.
设置一个会话值,表示用户已成功登录,在您想要保护的每个页面上检查它,如果未设置该值,则重定向到登录。
Set a session value that signifies that a user has successfully logged in, check for it on every page you want secured, redirect to login if that value isn't set.