diff options
author | Evan Prodromou <evan@status.net> | 2010-01-11 00:45:26 -0800 |
---|---|---|
committer | Evan Prodromou <evan@status.net> | 2010-01-11 00:45:26 -0800 |
commit | 8809e577b2c8cf1b8b187840aaf9674136929ec7 (patch) | |
tree | 28ed1e16f26d55510402f928ed9e484f0670cf01 /lib/util.php | |
parent | ad63a9518cb77d548e61fb39d05f8066733c326d (diff) | |
parent | 92deb35bc4dbd4203bce93bffec4cfb58eab032c (diff) |
Merge branch 'sessionidparam' into 0.9.x
Conflicts:
lib/command.php
Diffstat (limited to 'lib/util.php')
-rw-r--r-- | lib/util.php | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/lib/util.php b/lib/util.php index 23a22ad8c..1237d718b 100644 --- a/lib/util.php +++ b/lib/util.php @@ -171,15 +171,27 @@ function common_ensure_session() if (common_config('sessions', 'handle')) { Session::setSaveHandler(); } + if (array_key_exists(session_name(), $_GET)) { + $id = $_GET[session_name()]; + common_log(LOG_INFO, 'Setting session from GET parameter: '.$id); + } else if (array_key_exists(session_name(), $_COOKIE)) { + $id = $_COOKIE[session_name()]; + common_log(LOG_INFO, 'Setting session from COOKIE: '.$id); + } + if (isset($id)) { + session_id($id); + setcookie(session_name(), $id); + } @session_start(); if (!isset($_SESSION['started'])) { $_SESSION['started'] = time(); - if (!empty($c)) { + if (!empty($id)) { common_log(LOG_WARNING, 'Session cookie "' . $_COOKIE[session_name()] . '" ' . ' is set but started value is null'); } } } + common_debug("Session ID = " . session_id()); } // Three kinds of arguments: @@ -825,9 +837,39 @@ function common_path($relative, $ssl=false) } } + $relative = common_inject_session($relative, $serverpart); + return $proto.'://'.$serverpart.'/'.$pathpart.$relative; } +function common_inject_session($url, $serverpart = null) +{ + if (common_have_session()) { + + if (empty($serverpart)) { + $serverpart = parse_url($url, PHP_URL_HOST); + } + + $currentServer = $_SERVER['HTTP_HOST']; + + // Are we pointing to another server (like an SSL server?) + + if (!empty($currentServer) && + 0 != strcasecmp($currentServer, $serverpart)) { + // Pass the session ID as a GET parameter + $sesspart = session_name() . '=' . session_id(); + $i = strpos($url, '?'); + if ($i === false) { // no GET params, just append + $url .= '?' . $sesspart; + } else { + $url = substr($url, 0, $i + 1).$sesspart.'&'.substr($url, $i + 1); + } + } + } + + return $url; +} + function common_date_string($dt) { // XXX: do some sexy date formatting |