zoukankan      html  css  js  c++  java
  • header 跳转时报错误。Header may not contain more than a single header, new line detected

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

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

    先贴一下代码:

    class advertJumpUrl
    {
        /**
         * 广告唯一的key
         * @return array
         */
        private static function aGetKey()
        {
            $sKey = Ko_Tool_Input::VClean("r","k",Ko_Tool_Input::T_STR);
            $sKey = appsrandcpmMFacade_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 appsrandcpmMFacade_LogApi::sDecrypt($sUrl);
        }
    
        /**
         * 程序执行
         */
        public static function vRun()
        {
            $aPara = self::aGetKey();
            $sUrl = self::sGetUrl();
    //        $sUrl = rawurldecode($sUrl);
            if($aPara && $sUrl) {
                // 记录点击事件
                appsrandcpmMFacade_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。发现不行。

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

    urlencode 和rawurlencode 的区别:

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

    参考文档:

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

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

  • 相关阅读:
    真爱 vs. 种姓:新一代印度人的婚恋观
    美国司法部解禁guns打印技术
    特朗普访英,吃瓜群众却只想看《真爱至上》
    Semaphore(信号量)
    RLock(递归锁)
    用python编写九九乘法表
    php传值和传引用的区别
    post请求的header
    Content-type详解
    thinkphp5 学习笔记
  • 原文地址:https://www.cnblogs.com/wangkongming/p/7234478.html
Copyright © 2011-2022 走看看