我有参数:
http://example.com?ex=http://la.net?c1=a1&c2=a2&c3=a3
我想重定向到这个 URL,但是当我这样做时,我正在进入
http://example.com?ex=http://la.net?c1=a1
我知道这是因为&
标志...
我有参数:
http://example.com?ex=http://la.net?c1=a1&c2=a2&c3=a3
我想重定向到这个 URL,但是当我这样做时,我正在进入
http://example.com?ex=http://la.net?c1=a1
我知道这是因为&
标志...
您应该对传递给 URL 的参数进行编码:
$url = "http://example.com?ex=".urlencode("http://la.net?c1=a1&c2=a2&c3=a3");
header('Location: '.$url);
你应该能够做这样的事情:
header('Location: http://example.com?ex=' . urlencode($_GET['ex']));
urlencode()接受一个字符串并更改字符,使该字符串可以作为 url 中的值传递,这样它就不会影响整个 url。
尝试在参数值中使用&
而不是。&
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);