不打印缓冲的内容
php : view.php
<h1>hello world</h1>
php: index.php
require('view.php');
如果两个文件都位于根 mysite.com
上,
如果我访问 mysite.com/index.php
我应该得到 ' hello world'
如果我访问 mysite.com/view.php
我应该不会显示任何内容。
我一直在寻找一些 .HTACCESS 方法,但欢迎任何其他建议:)
结论:希望用户无法看到视图纯文本,而只允许必需的
或 get_file_contents()
读取文件。因此只能在服务器内读取该文件。
php : view.php
<h1>hello world</h1>
php: index.php
require('view.php');
if both files are on root mysite.com
if I access mysite.com/index.php
I should get 'hello world'
if I access mysite.com/view.php
I should get Nothing displayed.
I was looking for some .HTACCESS method but any other suggestions are welcomed :)
Conclusion: wish the user to not be able to see the view plain text, and only allow the required
or get_file_contents()
to read the files. So read the file only within server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
处理此问题的最佳方法是让包含文件永远不会在 Web 根目录之外访问,因为它们永远无法通过浏览器访问。
即您的文件结构将是:
您可以设置 PHP 的
include_path
以包含includes/
目录,这样您的包含文件中也不需要显式包含路径。The best way to handle this is to have your include files that are never intended to be accessed outside the web root, where they can never be accessed via a browser.
i.e. your file structure would be:
You can set PHP's
include_path
to include theincludes/
directory so your includes don't need to have a path explicitly in them, too.不要打印你的输出。使用输出数据创建一些变量(例如:
$tmp
)并将其打印在index.php
中Don't print your output. Make some variable (for example:
$tmp
) with output data and print it inindex.php
有 .htaccess 的东西你可以做
这并不完全是你想要的,但我认为如果你将它与 ceejayoz 的答案结合起来,它应该可以工作
there is .htaccess stuff you can do
this isnt going to be exactly what you want, but i think if you combine this with ceejayoz's answer, it should work