您在這裡

drupal其它根目錄讀取session問題

Alma's 的頭像
Alma 在 2014-04-08 (二) 17:51 發表

請教各位:

目前在drupal目錄下建立test.php頁面可以讀到drupal網站session的值
<?php
define('DRUPAL_ROOT', getcwd());
require_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user;
print_r ($user);
?>

若是建立在drupal目錄下的新目錄夾放置test.php頁面就讀不到session
嘗試過將define('DRUPAL_ROOT', getcwd());改為建立新目錄夾的路徑:
<?php define('DRUPAL_ROOT', '/var/www/clients/client1/web15/web');
require_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user;
print_r ($user);?>

就讀不到,詢問各位有人試過在drupal目錄下的新目錄夾底下建立php頁面讀取session?

Kay.L:

哈~謝謝

實作找到$cookie_domain,輸入域名
settings.php
$cookie_domain = 'xxx.xxx.xxx.com';

在位於域名底下的drupal資料夾中新增web資料夾放置test.php檔,裡面的程式:
<?php
define('DRUPAL_ROOT', '/var/www/xxx.xxx.xxx.com/web');
require_once('../includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user;
print_r ($user);
?>

出現下列error訊息 ,請問是用法錯誤嗎?
Warning: require_once('/var/www/xxx.xxx.xxx.com/web/includes/errors.inc) [function.require-once]: failed to open stream: No such file or directory in '/var/www/xxx.xxx.xxx.com/web/includes/bootstrap.inc on line 2270

Fatal error: require_once() [function.require]: Failed opening required ''/var/www/xxx.xxx.xxx.com/web/includes/errors.inc' (include_path='.:/usr/local/php5/lib/php') in '/var/www/xxx.xxx.xxx.com/web/includes/bootstrap.inc on line 2270

Kay.L:

目前我試出來了
謝謝您的指點

配合域名,
路徑測試去掉web
<?php
define('DRUPAL_ROOT', '/home/www/xxx.xxx.xxx.com');
require_once('../includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user; // This makes the user's $user object available to my script
print_r ($user);
?>