0

我正在开发一个使用 drupal 功能的独立应用程序,但遇到了一些麻烦。首先,我的应用程序必须检查用户是否可以访问此应用程序,如果他没有权限,则显示错误消息。如果用户已登录并具有权限,我的应用程序必须向他显示一些操作...首先我在 Apache 中创建了子域,例如我将其命名为:myapps.site.com。问题是:当未经授权的用户输入这个地址时,site.com 的主页被加载(只有没有图片的文本),不是我的页面有错误消息,但是当他打印 myapps.site.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 中的基本路径是 site.com,默认情况下 drupal_bootstrap 加载主页的内容。

4

2 回答 2

1

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

于 2012-12-08T05:46:00.423 回答
1

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

另请检查此https://www.drupal.org/node/2333361,如果我发现其他内容或问题再次出现,我将再次发布。

于 2014-09-05T12:16:59.437 回答