header 跳转时报错误。Header may not contain more than a single header, new line detected
2017-07-25 15:39
525 查看
我在用php的header做跳转时,报错误。
Header may not contain more than a single header, new line detected
先贴一下代码:
在网上搜索一下,是因为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
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 = \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。发现不行。
有人建议用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
相关文章推荐
- 关于IAR报 more than one storage class may not be specified 错误的问题
- Read in text file line by line php - newline not being detected
- iOS--错误集锦--pushing the same view controller instance more than once is not supperted
- codeblocks中Error:new types may not be defined in a return type错误
- Qt 错误"new types may not be defined in a return type" error
- new types may not be defined in a return type错误
- XCode打包出现does not contain a single boundle错误解决办法
- A new session could not be created. (Original error: Requested a new session but one was in progress) )错误解决办法
- 错误记录--Multiple constructor definitions found. Constructor may not be defined in
- 重新postgresql出现错误:Problem running post-install step. Installation may not complete correctly. The database cluster initialisation failed.
- PLS-00231错误:function name may not be used in SQL
- Unable to configure Windows to Trust the Fiddler Root certificate.The LOG tab may contain more infor
- Mapped Statements collection does not contain value for错误解决方法
- iOS开发中,Xcode编译错误:does not contain bit code
- 关于QT中奇数个汉字出现newline in constant的错误
- 关于“Error: Net "gdfx_temp0", which fans out to "***:inst4|BIN", cannot be assigned more than”错误
- 通过ant来批量执行jmeter脚本,并生成报告(附: 生成报告时报“Content is not allowed in prolog”这个错误的解决方案)
- Qt 使用qmake 遇到 warning LNK4042: object specified more than once; extras ignored 错误的处理办法
- 消除ADB错误“more than one device and emulator”的方法
- 关于Result Maps collection does not contain value for....错误原因总结