Skip to content

Commit

Permalink
Replaces uses of deprecated constant SID with calls to session_id()
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <[email protected]>
  • Loading branch information
Sesquipedalian committed Dec 25, 2024
1 parent c978ec9 commit 031326b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions Sources/QueryString.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,14 @@ public static function isFilteredRequest(array $value_list, string $var): bool
*/
public static function ob_sessrewrite(string $buffer): string
{
// If Config::$scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
if (Config::$scripturl == '' || !defined('SID')) {
// If Config::$scripturl is set to nothing, or the session ID is not defined (SSI?) just quit.
if (Config::$scripturl == '' || session_id() === false) {
return $buffer;
}

// Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit().
if (empty($_COOKIE) && SID != '' && !BrowserDetector::isBrowser('possibly_robot')) {
$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote(Config::$scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\??/', '"' . Config::$scripturl . '?' . SID . '&amp;', $buffer);
if (empty($_COOKIE) && session_id() != '' && !BrowserDetector::isBrowser('possibly_robot')) {
$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote(Config::$scripturl, '/') . '(?!\?' . preg_quote(session_id(), '/') . ')\??/', '"' . Config::$scripturl . '?' . session_id() . '&amp;', $buffer);
}
// Debugging templates, are we?
elseif (isset($_GET['debug'])) {
Expand All @@ -441,11 +441,11 @@ public static function ob_sessrewrite(string $buffer): string
)
) {
// Let's do something special for session ids!
if (defined('SID') && SID != '') {
if (session_id() != '') {
$buffer = preg_replace_callback(
'~"' . preg_quote(Config::$scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~',
'~"' . preg_quote(Config::$scripturl, '~') . '\?(?:' . session_id() . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~',
function ($m) {
return '"' . Config::$scripturl . '/' . strtr("{$m[1]}", '&;=', '//,') . '.html?' . SID . ($m[2] ?? '') . '"';
return '"' . Config::$scripturl . '/' . strtr("{$m[1]}", '&;=', '//,') . '.html?' . session_id() . ($m[2] ?? '') . '"';
},
$buffer,
);
Expand Down
10 changes: 5 additions & 5 deletions Sources/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2237,8 +2237,8 @@ public static function redirectexit(string $setLocation = '', bool $refresh = fa
}

// Put the session ID in.
if (defined('SID') && SID != '') {
$setLocation = preg_replace('/^' . preg_quote(Config::$scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\??/', Config::$scripturl . '?' . SID . ';', $setLocation);
if (session_id() != '') {
$setLocation = preg_replace('/^' . preg_quote(Config::$scripturl, '/') . '(?!\?' . preg_quote(session_id(), '/') . ')\??/', Config::$scripturl . '?' . session_id() . ';', $setLocation);
}
// Keep that debug in their for template debugging!
elseif (isset($_GET['debug'])) {
Expand All @@ -2256,11 +2256,11 @@ public static function redirectexit(string $setLocation = '', bool $refresh = fa
Sapi::isSoftware([Sapi::SERVER_APACHE, Sapi::SERVER_LIGHTTPD, Sapi::SERVER_LITESPEED])
)
) {
if (defined('SID') && SID != '') {
if (session_id() != '') {
$setLocation = preg_replace_callback(
'~^' . preg_quote(Config::$scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
'~^' . preg_quote(Config::$scripturl, '~') . '\?(?:' . session_id() . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
function ($m) {
return Config::$scripturl . '/' . strtr("{$m[1]}", '&;=', '//,') . '.html?' . SID . (isset($m[2]) ? "{$m[2]}" : '');
return Config::$scripturl . '/' . strtr("{$m[1]}", '&;=', '//,') . '.html?' . session_id() . (isset($m[2]) ? "{$m[2]}" : '');
},
$setLocation,
);
Expand Down

0 comments on commit 031326b

Please sign in to comment.