使用include时无法直接访问脚本 [英] No direct script access when using include

查看:141
本文介绍了使用include时无法直接访问脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP支持的CMS网站。我想在PHP脚本中包含 database.php 。 database.php位于config文件夹中,并具有数据库连接详细信息(pass,db_name等)。

I have a PHP powered CMS website. I'd like to include database.php in a PHP script. database.php is in the config folder and has the db connections details (pass, db_name etc).

以下是脚本:

<?php 
  echo __DIR__ ."<br /><br />"; 
  //make sure your assumptions on directories and path are correct for the 
  //include below

  include '../application/config/database.php';

?>

运行脚本,我收到此消息:

Running the script, I get this message:


/ Applications / XAMPP / xamppfiles / htdocs / tslocal / textbook_scripts

/Applications/XAMPP/xamppfiles/htdocs/tslocal/textbook_scripts

无法直接访问脚本。

database.php 的第一行是这一行:

<?php defined('SYSPATH') or die('No direct script access.');

我猜这个CMS已经以某种方式保护配置文件,这阻止了我它。什么是没有直接脚本访问?谷歌为我提供了许多寻求添加此功能的人的例子。我希望将其删除。可能?可能性有多大?我如何告诉PHP让我访问database.php?

I'm guessing that the CMS has somehow "protected" the config file which is preventing me from including it. What is "No direct script access"? Google gives me lots of examples of people seeking to add this functionality. I wish to remove it. Possible? Likely? How do I tell PHP to let me access database.php?

推荐答案

实现此目的的基本方法是在应用程序中的某处(在加载database.php之前)有一行代码:

The basic way for going about this is somewhere in the application (prior to the loading of database.php) there is a line something along the lines of:

define( 'APPLICATION_LOADED', true );

在database.php中,对此进行检查,类似于:

In the database.php there is a check being performed against this, similar to:

if( !defined('APPLICATION_LOADED') || !APPLICATION_LOADED ) {
    die( 'No direct script access.' );
}

查看database.php以及它包含的任何文件以确定它是如何检查的查看脚本是否被直接访问。如果您想在脚本中包含该文件,则可以模仿必要的条件。

Look in database.php and whatever files it includes to determine how it is checking to see if the script is being directly accessed or not. Then you can mimic the conditions necessary if you would like to include that file in your script.

这篇关于使用include时无法直接访问脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆