成功登录后允许重定向

时间:2021-01-28 13:36:20

标签: php .htaccess

我有一个 .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 执行此操作?

1 个答案:

答案 0 :(得分:0)

允许 execute.php in ht 访问并添加会话检查。

session_start();
if($_SESSION["loggedIn"] != true){
       echo 'not logged in';
       header("Location: apiLogin.php");
       exit;
    }

在 apiLogin 上,当用户登录时将 session 设置为 true

$_SESSION["loggedIn"] = true;