示例#1
0
文件: Subs.php 项目: norv/EosAlpha
function redirectexit($setLocation = '', $refresh = false)
{
    global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
    // In case we have mail to send, better do that - as obExit doesn't always quite make it...
    if (!empty($context['flush_mail'])) {
        AddMailQueue(true);
    }
    $add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
    if ($add) {
        $setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
    }
    // Put the session ID in.
    if (defined('SID') && SID != '') {
        $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
    } elseif (isset($_GET['debug'])) {
        $setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
    }
    // Maybe integrations want to change where we are heading?
    HookAPI::callHook('integrate_redirect', array(&$setLocation, &$refresh));
    if (!empty($modSettings['simplesef_enable'])) {
        SimpleSEF::fixRedirectUrl($setLocation, $refresh);
    }
    // We send a Refresh header only in special cases because Location looks better. (and is quicker...)
    if ($refresh) {
        header('Refresh: 0; URL=' . strtr($setLocation, array(' ' => '%20')));
    } else {
        header('Location: ' . str_replace(' ', '%20', $setLocation));
    }
    // Debugging.
    if (isset($db_show_debug) && $db_show_debug === true) {
        $_SESSION['debug_redirect'] = $db_cache;
    }
    obExit(false);
}