简体   繁体   中英

How can i share one session across two different sites in PHP and Drupal

Am building a site using PHP and Drupal. Basically PHP is handling the Front-end of the site and Drupal Backend. Some pages on site when you click on them they redirect you to Drupal site.

So here is the part where am confused. Am trying to set a session in PHP pages but when i click on some pages which redirects me to drupal and it says the session is not set. How can i share one session in both sides, PHP pages and Drupal Pages

This isn't a straight forward thing to do. You're going to need to bootstrap Drupal in your other PHP application to gain access to Drupals sessions

require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
$session_id = session_id();

This would give you the session ID and access to Drupals session database table, which you could perform a query against to pull out all the current session info like:

$query = db_query("SELECT * FROM sessions WHERE session_id = :session_id", 
array(':session_id' => $session_id));
$session = $query->fetchObject;

With a bit more detail on what exactly you want to be passed across the two sites there may be a better way of doing it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM