是否可以在 PHP 中包含一些东西without传递传递给原始脚本的变量?
我正在使用 Joomla,并且我收到了错误记录here https://stackoverflow.com/questions/8356683/joomla-error-illegal-variable-files-or-env-or-get-or-post-or-cookie-or-s(“非法变量......”)。 php 脚本是一个 AJAX 脚本,它将数据发送回浏览器,因此该脚本需要大量 POST 变量,执行数据库查询,然后回显结果。我正在尝试加强安全性,因此我在此脚本中添加了一个包含内容,以使用内置的 Joomla 模块对用户进行身份验证。我的想法来自here https://stackoverflow.com/questions/2445549/how-to-get-current-joomla-user-with-external-php-script用于用户身份验证脚本。
身份验证脚本适用于某些页面,但对于其他页面,我收到上述错误。所以我想包含身份验证脚本而不向其传递任何变量。这可能吗?
编辑:这里有更多细节。
在ajax脚本中我有这个:
<?php
include '/var/www/joomla-auth.php';
...
下面是脚本,基本上包含的“joomla-auth.php”脚本负责获取 mysql 查询的用户名和密码。 joomla-auth 的内容:
<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
/* Create the Application */
$mainframe =& JFactory::getApplication('site');
/* Make sure we are logged in at all. */
if (JFactory::getUser()->id == 0)
die("Access denied: login required.");
$user =& JFactory::getUser();
我很确定是定义或要求行引发了错误:
非法变量 _files 或 _env 或 _get 或 _post 或
_cookie 或 _server 或 _session 或传递给脚本的全局变量。
如上面第一个链接中所述。
EDIT 2:
“joomla-auth.php”脚本创建 $username 和 $password 变量,然后在 AJAX 脚本中使用它们。我在 AJAX 脚本的顶部尝试了这个:
function get_creds(){
include '/var/www/joomla-auth.php';
return Array($username,$password);
}
$creds = get_creds();
$username = $creds[0];
$password = $creds[1];
....
但 $_POST 变量仍然被传递到 /var/www/joomla-auth.php :-(