PHP对特定页面使用header() [英] PHP use header() for a specific page
本文介绍了PHP对特定页面使用header()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果用户未登录,我试图阻止查看JavaScript页面(.js),
我想从index.php页面上编写404或403标头,这是怎么做的?
注意:我不想使用chmod,因为它会全局更改文件权限,而不是访问者权限
I'm trying to block viewing a javascript page (.js) if user is not logged in,
i wanna do it from the index.php page to write a 404 or 403 header, how is it done ?
note: i dont wanna use chmod since it globally change the file permissions and not for the visitor
header("HTTP/1.0 404 Not Found", "js.js");
js.js是一个错误的参数,只是我想要它或类似功能的示例,
js.js is a false parameter, just a sample of how i want it or something does a similar thing,
推荐答案
为此,您将需要一个单独的脚本. 如
You will need a seperate script for this. Such as
file.php
$file = $_GET['file'];
//whitelist files
$filelist = array('js.js');
if(in_array($file, $filelist))
{
header('Cache Control: No-store');
header('Content-Disposition:inline;filename="' . $file . '"');
include "../files/$file";
}
使用它
<script src="files.php?file=js.js"></script>
并将文件放置在不可访问的位置
and put your files in a non web accessible location
这篇关于PHP对特定页面使用header()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文