drupal_bootstrap and subdomains



我正在开发一个独立的应用程序,它使用drupal函数,我遇到了一些麻烦。首先,我的应用程序必须检查用户是否有权访问该应用程序,如果他没有权限,则显示错误消息。若用户已登录并拥有权限,我的应用程序必须向他显示一些操作。。。首先,我在Apache中创建了子域,例如我将其命名为:myapps.site.com。问题是:当未经授权的用户输入此地址时,会加载site.com的主页(只有文本而没有图片),而不是我的带有错误消息的页面,但当他打印myapps.ite.com/index.php时,一切都好,并加载错误消息。当授权用户进入此页面时,一切正常。我已经检查过,问题出在上

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>'; ?>

据我所知,这个问题也可能会出现,因为这是settings.php中的子域和基本路径,默认情况下drupal_bootstrap加载主页的内容。

使用http://drupal.org/project/domain对于这种事情,不要自己编写代码。

尝试从性能选项中清除缓存。还取消选中选项"缓存匿名用户的页面",它对我有效(直到现在)

还要检查这个https://www.drupal.org/node/2333361,如果我发现其他问题或问题再次出现,我会再次在那里发帖。

最新更新