我正在开发一个独立的应用程序,它使用drupal函数和我遇到了一些麻烦。首先,我的应用程序必须检查是否有用户访问此应用程序,如果他没有权限显示错误消息。如果用户已登录并且拥有许可权,我的应用程序必须向他展示一些操作...首先,我在Apache中创建了子域,例如我将其命名为: myapps.site.com。麻烦的是:当未经授权的用户输入这个地址时,site.com的主页被加载(只有没有图片的文字),而不是我的页面有错误信息,但是当他打印myapps.site.com/index.php时,一切正常,加载错误消息。当授权用户进入此页面时,一切正常。我已签,这个问题是与drupal_bootstrap和子域名
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
这里是我的代码示例:
<?php
chdir('/www/mysite/');
require_once './includes/bootstrap.inc';
require_once './includes/form.inc';
// Here is problem
// if I comment this and show only err message everything is also OK
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user;
// Here I am loading additional info to check if the user has access
profile_load_profile(&$user);
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="styles/styles.css" />
<script src="jscripts/jQuery.js"></script>
<title>app</title>
</head>
<body>';
// here i check user priviliges
if (!$user->uid || $user->profile_is_priviliged == FALSE)
{
echo 'some err msg';
}
else
{
echo 'some actions';
}
echo '</body></html>'; ?>
正如我已经明白这个问题可能还会上涨,因为这是在设置子域和基本路径.php是site.com,默认情况下,drupal_bootstrap加载主页的内容。