PHP头函数修改查询字符串,如果它是一个url


PHP header function modifying query string if it is an url

这是非常奇怪的看到php头函数修改查询字符串,如果它是一个URL。我使用了这样的header函数

header('Location: http://www.example.com/account-type?goto=http://www.google.com/hello');
这是重定向到http://www.example.com/account-type?goto=http/hello修改后的查询字符串

如果我使用相对URL

header('Location: /account-type?goto=http://www.google.com/hello');
这将重定向到http://www.example.com/account-type?goto=http://www.google.com/hello

谁能告诉我如何解决这个问题?

我猜这只是编码的问题。试试这个:

$url = urlencode('http://www.google.com/hello');
header('Location: http://www.example.com/account-type?goto=' . $url);