English 中文(简体)
防止直接查阅实验室档案
原标题:Preventing direct access to php files
  • 时间:2011-08-03 17:34:35
  •  标签:
  • php
  • apache

这方面是我档案结构的一个例子。

/index.php
/inc
/inc/file1.php
/inc/file2.php
/inc/file3.php
/search.php

index.php includes() file1.php, file2.php, and file3.php. And I want them to be accessible by index.php only.

有哪些最可取的解决办法?

增 编

最佳回答

将它们排除在文件之外:

/documentroot/index.php
/inc/file1.php
/inc/file2.php
/inc/file3.php

因此,无法直接接触他们。

问题回答

指数。 你可以这样界定:

define( RESTRICTED ,1);

Then in your other pages you put this after <?php

if(!defined( RESTRICTED ))exit( No direct script access allowed! );

When the other pages are accessed directly the code above sees that RESTRICTED has not been set, hence it will exit.

a. 编造“htaccess”文档,将其放在“inc”上。

<Files .htaccess>
order allow,deny
deny from all
</Files>

<Files *.php>
order allow,deny
deny from all
</Files>

或将此事放在你想要nie的档案上。

if(strrchr($_SERVER[ PHP_SELF ], / )== /file_name.php ){die;} // not good for ajax include




相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签