简体   繁体   English

从.html页面重定向非登录用户?

[英]Redirecting non logged-in users from .html pages?

I am doing some patchwork on an old and outdated site. 我正在一个旧的和过时的站点上做一些拼凑。 It's based on PHP but there is no framework, and a bunch of pages are static (.html). 它基于PHP,但是没有框架,并且一堆页面是静态的(.html)。

I created a simple login system for the site, but now the client wants the system to work for the static pages as well - basically, a member who isn't logged in should be redirected from them. 我为该站点创建了一个简单的登录系统,但是现在客户端希望该系统也能用于静态页面-基本上,未登录的成员应从其中重定向。

However, since there is no session, no include and no PHP code in general, I'm unsure as to how to proceed. 但是,由于通常没有会话,没有包含,也没有PHP代码,所以我不确定如何进行。 My only idea is to send an AJAX request before the page loads to check if there's a session, and do a client-side redirect if not, but that seems a bit sketchy. 我唯一的想法是在页面加载之前发送AJAX请求,以检查是否存在会话,如果没有,则执行客户端重定向,但这似乎有些粗略。

The client doesn't want to use an HTTP authentication popup, but rather the new PHP login system. 客户端不希望使用HTTP身份验证弹出窗口,而是希望使用新的PHP登录系统。

Has someone been in this situation? 有人来过这种情况吗? Any solutions that don't involve me going into every file, renaming them to .php and updating all the links on the site to reflect that would be a lifesaver. 任何不涉及我进入每个文件的解决方案,将它们重命名为.php并更新网站上的所有链接以反映这一点,那将是一个救命稻草。

The solution to this problem I think is really AJAX 我认为这个问题的解决方案实际上是AJAX

But if HTML pages in apache or php server, you can create a .htaccess to read if page is .html and pass to page_check.php and script check if logged and redirect or simple read the .html file and put content on the screen. 但是,如果apache或php服务器中的HTML页面,则可以创建一个.htaccess来读取页面是否为.html并传递给page_check.php并通过脚本检查是否已登录并重定向或简单地读取.html文件并将内容显示在屏幕上。

htaccess htaccess的

RewriteRule ^(.*)\.html$ check_page.php?page=$1 [L, QSA]

PHP PHP

<?php
$page = $_GET['page'];

$file = getcwd() . $page;
// check if logged and redirect
...

// if not redirected then 
if(file_exists($page)){
    $content = file_get_contents($file);
    header('Content-Type: text/html');
    echo $content;
} else {
    // redirect if file no exists
    header('Location: 404.php');
}

?>

I hope that gives you a direction. 我希望这会给您一个方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM