One important point to remember (today it took me 7 hours to find): if you want to pass a link containing blank spaces through urlencode() and then decode it to use in href attribute of an anchor or link, you must not use urldecode(). href does not include blank spaces.

e.g.: header("Location: somepage.php?link=" . urlencode("user/files/some file.pdf"));

and at somepage.php:

DO NOT WRITE: echo "<a href=" . urldecode($_GET["link"]) . " >Click to download</a>";

INSTEAD WRITE: echo "<a href=" . $_GET["link"] . " >Click to download</a>";