避免直接调用某些文件

类别:编程语言 点击:0 评论:0 推荐:

在我们的网站中,有些目录下的文件,是不允许客户直接通过URL的方式访问的,因此,我们就需要使用一些方法来限制,实现这种功能有以下几种方式:

.htaccess文件

建立一.htaccess文件

------------------------------------------------

# options the .htaccess files in directories can override.

   # Edit apache/conf/httpd.conf to AllowOverride in .htaccess

   # AllowOverride AuthConfig

 

# Stop the directory list from being shown

  Options -Indexes

 

# Controls who can get stuff from this server.

  Order Deny,Allow

  Deny from all

  Allow from localhost

PHP的方式实现
<?php
if (eregi("mainfile.php",$PHP_SELF)) {

    Header("Location: index.php");

    die();

}

?>

本文地址:http://com.8s8s.com/it/it28330.htm