Products and Services
Find the right tools for your business. Select the right components and build the perfect web site.
I recently needed to pass a URL in the get string as I redirected a form submission to an external server. The URL had parameters which clearly would have conflicted with the string and would have been perceived as additional parameters of the original string.
http://www.yoursite.com
/page.asp?redirecturl=www.mysite.com
/optin.php?thankyou=1
URLs are limited in the number of characters that are permitted and several of those characters are reserved with special functions regardless of where they appear in the string. This created a problem if you need to pass a URL with parameters or any special characters in the URL string.
In order to pass a URL in a URL string you will need to encode it which will convert all characters aside from alphanumeric dash (-) and underscore (_) to their equivalents with % and two hex digits. In PHP you can use the urlencode() function and the equivalent urldecode() function for converting the string back.
$url = urlencode('www.getthingirl.com
/optin.php?thankyou=1');
header("Location: http://www.yoursite.com
/page.asp?redirecturl=$url");
One note:
You will run into problems with certain characters such as ampersands (&). These should be passed as their html entity equivalents. So when passing url strings with parameters in PHP use the htmlentities() function first.
$url = urlencode(htmlentities('www.getthingirl.com
/optin.php?thankyou=1'));
header("Location: http://www.yoursite.com
/page.asp?redirecturl=$url");