首页 > 解决方案 > 登录成功后允许重定向

问题描述

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

标签: php.htaccess

解决方案


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

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

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

$_SESSION["loggedIn"] = true;


推荐阅读