コード例 #1
0
ファイル: limonade.php プロジェクト: plus3network/PHPHelpers
/**
 * Http redirection
 *
 * @param string $params,...
 * @return void
 */
function redirect_to($params)
{
    # [NOTE]: (from php.net) HTTP/1.1 requires an absolute URI as argument to » Location:
    # including the scheme, hostname and absolute path, but some clients accept
    # relative URIs. You can usually use $_SERVER['HTTP_HOST'],
    # $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative
    # one yourself.
    # TODO make absolute uri
    if (!headers_sent()) {
        $params = func_get_args();
        $uri = call_user_func_array('url_for', $params);
        stop_and_exit(false);
        header('Location: ' . $uri);
        exit;
    }
}
コード例 #2
0
ファイル: limonade.php プロジェクト: soitun/CRMx
/**
 * Http redirection
 * 
 * Same use as {@link url_for()}
 * By default HTTP status code is 302, but a different code can be specified
 * with a status key in array parameter.
 * 
 * <code>
 * redirecto('new','url'); # 302 HTTP_MOVED_TEMPORARILY by default
 * redirecto('new','url', array('status' => HTTP_MOVED_PERMANENTLY));
 * </code>
 * 
 * @param string or array $param1, $param2... 
 * @return void
 */
function redirect_to($params)
{
    # [NOTE]: (from php.net) HTTP/1.1 requires an absolute URI as argument to » Location:
    # including the scheme, hostname and absolute path, but some clients accept
    # relative URIs. You can usually use $_SERVER['HTTP_HOST'],
    # $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative
    # one yourself.
    # TODO make absolute uri
    if (!headers_sent()) {
        $status = HTTP_MOVED_TEMPORARILY;
        # default for a redirection in PHP
        $params = func_get_args();
        $n_params = array();
        # extract status param if exists
        foreach ($params as $param) {
            if (is_array($param)) {
                if (array_key_exists('status', $param)) {
                    $status = $param['status'];
                    unset($param['status']);
                }
            }
            $n_params[] = $param;
        }
        $uri = call_user_func_array('url_for', $n_params);
        $uri = htmlspecialchars_decode($uri, ENT_NOQUOTES);
        stop_and_exit(false);
        send_header('Location: ' . $uri, true, $status);
        exit;
    }
}