什么是正确和安全的vay通过url传递url

I want to pass url (or even several urls) through url, i.e. use url like http://domain/file.php?url1=...&url2=.... The question is how to make such urls safe and working. Will urlencode() help.

BTW, if I do urlencode($url), do I need to urldecode() before doing header("Location: $url")

Thank you in advance!

Will urlencode() help.

yes.

BTW, if I do urlencode($url), do I need to urldecode() before doing header("Location: $url")

no. you'd need to encode the single urls which go to the final url, i.e.

$url1= "http://www.example.com";
$final = "http://yourdomain.com?url1=".urlencode($url1);