开发者

PHP - & in header()

I have the parameter:

http://example.com?ex=http://la.net?c1=a1&c2=a2&c3=a3

I want to redirect to this URL, but while I do开发者_Go百科 it, I'm getting into

http://example.com?ex=http://la.net?c1=a1

I know that it's because of the & sign...


You should encode parameters that is passed to URL:

$url = "http://example.com?ex=".urlencode("http://la.net?c1=a1&c2=a2&c3=a3");
header('Location: '.$url);


you should just be able to do something like this:

header('Location: http://example.com?ex=' . urlencode($_GET['ex']));

urlencode() takes a string and changes the characters in a way where the string can then be passed as a value within an url so that it does not effect the entire url.


Try using & instead of & in the parameter value.

function fixURL($curURL){
   return preg_replace("/&/","&",$curURL);
}
$param1 = "http://la.net?c1=a1&c2=a2&c3=a3";
$param2 = "http://la.net?c1=a1";
$param3 = "http://ladelala.net?c1=a1&c2=a2&c3=a3";
$url = "http://example.com?ex=".fixURL($param1) . "&ex2=".fixURL($param2) . "&ex3=".fixURL($param3);
header('Location: '.$url);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜