我在web根目录上有一个带有Drupal的Apache web服务器。我在根目录的子目录中也有一些非Drupal内容。我希望它能够使非Drupal内容不可访问,除非用户首先登录到Drupal。
我遇到过使用mod_auth_mysql (enter link description here)的情况,但这并不是我想要的。它要求用户登录两次(一次登录到Drupal,一次登录非Drupal内容)。
我设想的解决方案类似于让.htaccess运行脚本来确定用户是否已登录。这个脚本必须连接到Drupal系统。
是否可以使用.htaccess运行脚本来确定是否应该授予访问权限?
或者有更好的解决方案?
发布于 2012-07-18 00:16:20
我已经通过部分加载Drupal (通过DRUPAL_BOOTSTRAP_SESSION),然后检查全局$user来实现这一点。
<?php
$base_url = 'http://'.$_SERVER['HTTP_HOST'];
$drupal_path = "../../";
$cdir = getcwd();
chdir($drupal_path);
require_once 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
chdir($cdir);
global $user;
$access_granted = in_array('authenticated user', $user->roles);
if (!$access_granted):
//Show page
else:
//Show access denied
endif;
?>https://stackoverflow.com/questions/11518751
复制相似问题