php - 登录成功后允许重定向
问题描述
我有一个 .htaccess 拒绝访问我的所有文档,但登录页面除外,即apiLogin.php
. 如下面的代码所示:
<Limit GET POST>
order deny,allow
deny from all
allow from 127.0.0.1
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
DirectoryIndex apiLogin.php
<Files ~ "execute.php$">
Order Allow,Deny
Deny from All
allow from 127.0.0.1
</Files>
<Files ~ "printAPI.php$">
Order Allow,Deny
Deny from All
</Files>
<Files ~ "Orders.xml$">
Order Allow,Deny
Deny from All
</Files>
<Files ~ "Config.xml$">
Order Allow,Deny
Deny from All
</Files>
RewriteEngine On
RewriteRule (^|/)s_orderlist(/|$) - [F]
我希望我execute.php
允许apiLogin.php
在成功登录后进行重定向(表单已经对其进行了检查-但是我无法将其重定向到页面,因为 htaccess 拒绝了它/我需要一个例外)。我如何实现这一目标?我是通过 .htaccess 还是通过 php 执行此操作?
解决方案
允许execute.php
在 ht 访问并添加会话检查。
session_start();
if($_SESSION["loggedIn"] != true){
echo 'not logged in';
header("Location: apiLogin.php");
exit;
}
在 apiLogin 上,当用户登录时将会话设置为 true
$_SESSION["loggedIn"] = true;
推荐阅读
- windows - 在 .Appx 包安装结束时触发脚本 [UWP]
- android - 条纹结帐模式键盘涵盖小型设备上的输入和支付按钮
- python - 如何使用异步函数实现 ThreadPool?
- node.js - 使用带有投影和唯一验证的 Mongoose.js 创建文档
- python - 无法使用 Selenium Webdriver 打开超过最大数量的选项卡?
- javascript - AngularJS / Sqlite / Electron - 未知提供者:$dbServiceProvider
- python - 搅拌器:将创建半径锁定到鼠标移动
- python - 异常错误处理扰乱了我的变量
- c# - 如何使用原始媒体基础 API 实时同步视频和音频?
- javascript - 如何在本地状态下从此 API 编辑用户?