header 跳转时报错误。Header may not contain more than a single header, new line detected

我在用php的header作跳转时,报错误。php

Header may not contain more than a single header, new line detectedapp

先贴一下代码:编码

class advertJumpUrl
{
    /**
     * 广告惟一的key
     * @return array
     */
    private static function aGetKey()
    {
        $sKey = Ko_Tool_Input::VClean("r","k",Ko_Tool_Input::T_STR);
        $sKey = \apps\brand\cpm\MFacade_LogApi::sDecrypt($sKey);
        $aPara = explode('_', $sKey);
        return $aPara;
    }

    /**
     * 广告跳转的url
     * @return url
     */
    private static function sGetUrl()
    {
        $sUrl = Ko_Tool_Input::VClean("r","t",Ko_Tool_Input::T_STR);
        return \apps\brand\cpm\MFacade_LogApi::sDecrypt($sUrl);
    }

    /**
     * 程序执行
     */
    public static function vRun()
    {
        $aPara = self::aGetKey();
        $sUrl = self::sGetUrl();
//        $sUrl = rawurldecode($sUrl);
        if($aPara && $sUrl) {
            // 记录点击事件
            \apps\brand\cpm\MFacade_LogApi::vClick($aPara[1], $aPara[0]);
            header('HTTP/1.1 301 Moved Permanently');
            header('location:'.$sUrl);
            exit;
        }
        header('HTTP/1.1 301 Moved Permanently');
        header('location:/');
        exit;
    }
}
advertJumpUrl::vRun();

 

在网上搜索一下,是由于URL编码有问题。我尝试用urlencode 而后再urldecode。发现不行。url

有人建议用rawurlencode。我试了试,成功了。spa

urlencode 和rawurlencode 的区别:.net

urlencode 将空格则编码为加号(+)
rawurlencode 将空格则编码为加号(%20)code

 

参考文档:htm

https://stackoverflow.com/questions/16320403/getting-warning-header-may-not-contain-more-than-a-single-header-new-line-deteblog

http://www.jb51.net/article/24123.htm事件

相关文章
相关标签/搜索