您在這裡

drupal 自動登入問題

Alma's 的頭像
Alma 在 2014-06-05 (四) 11:58 發表

整合不同網站實作自動登入帳號,在Drupal index.php頁面中做登入判斷,以下列的方式實作,drupal網站會發生迴圈loading不出來

使用者若直接連到http://xx.xx.xx.xx/drupal 網站時,會轉向到另一個網站(http://xx.xx.xx.xx/web01),讓使用者從這先登入帳號,若有登入的記錄,就帶帳號session至http://xx.xx.xx.xx/drupal 網站做自動登入

再請教各位指點,謝謝

<?php
session_start();
$username = $_SESSION['test_user'];
session_write_close();
?>
<?php

/**
* @file
* The PHP page that serves all page requests on a Drupal installation.
*
* The routines here dispatch control to the appropriate handler, which then
* prints the appropriate page.
*
* All Drupal code is released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt.
*/

/**
* Root directory of Drupal installation.
*/
define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
require_once DRUPAL_ROOT . '/includes/session.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$user = user_load_by_name($username);
drupal_session_regenerate();
if($username == ''){
drupal_goto('http://xx.xx.xx.xx/web01'); (非drupal網站)
}else{
drupal_goto('http://xx.xx.xx.xx/drupal'); (drupal網站)
}