$value) { if ($pos = strpos($key, '_session_key')) { $apikey = substr($key, 0, $pos); } } if ($apikey && isset($_COOKIE[$apikey . '_ss'])) { // We're logged into Facebook Connect. // Use globals to remember some values, for fb_connect.module to use. $GLOBALS['_fb_connect_apikey'] = $apikey; // Rename the session id, so the Facebook Connect session is distinct from the original drupal session. $new_session_id = 'fb_connect.' . $_COOKIE[$apikey . '_session_key']; } } // Set the session name. if (isset($new_session_name)) { session_name($new_session_name); } // Set the session id. if (isset($new_session_id)) { if (!variable_get('fb_session_long_keys', TRUE)) { // Facebook appends user id, time and expiry info which is not necessary for uniqueness. Here we truncate that information to ensure the sid fits in sessions table. $new_session_id = substr($new_session_id, 0, 64); } if ($new_session_id != $orig_session_id) { session_id($new_session_id); if (isset($GLOBALS['_fb_connect_apikey'])) { // We can preserve the session state when going into fbconnect db_query("DELETE FROM {sessions} WHERE sid='%s'", $new_session_id); db_query("UPDATE {sessions} SET sid = '%s' WHERE sid = '%s'", $new_session_id, $orig_session_id); } } // User logged into facebook, but possibly not Drupal. If so, we do not want the cached page. $GLOBALS['conf']['cache'] = 0; } else { // No session from facebook, so make sure we're not using an out of date one. if (strpos($orig_session_id, 'fb_connect') === 0) { // Old fbconnect session can be deleted db_query("DELETE FROM {sessions} WHERE sid='%s'", $orig_session_id); session_id(md5(uniqid(microtime()) . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'])); } elseif (strpos($orig_session_id, 'fb_connect') === 0) { // Canvas session should not be deleted as it could be a user visiting both the website and an iframe app if (!$label) session_id(md5(uniqid(microtime()) . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'])); } } // If the session is contolled by Facebook, include our session implementation. if (isset($new_session_id)) { require('fb_session_impl.inc'); } else { // Session not controlled by facebook, use Drupal's session implemtation. require('includes/session.inc'); }