URGENT: Load an ENCODED URL using Header?

Hi Guys,

I really need your help, below is my code:

header(urlencode( 'Location: '.$url.'' ));

Will loading a encoded URL work or not?

My client is telling me this:

> Again, you must do a strpos() or whatever string locator function of PHP
> to
> extract out the unencoded URL.

Can someone please help me out here as this is urgent. Can someone show me an example of what he’s telling me to do please, im going crazy, I’ve now been working 12hrs coding and just need some help on this please.

Any help would be great!

Thank you guys!

I’m not entirely sure what your trying to accomplish. But, I think what your client is trying to say is that you don’t want to encode the entire URL.

For example, you have the following url:

Your code encodes the entire URL. What I think your client is pointing out, is that you only want to encode the text after the question mark sign like this:

$parsed_url = explode("?",$url);
header('Location: '.$parsed_url[0]."?".urlencode($parsed_url[1]).'' ); 

I’ve not tested this code, but you might also look into using the parse_url php function.

What he is saying is not all the URL is being loaded, let say im loading

i have the following:


echo $url;

But only google.com?id=3 is being echo’d out and not the rest of the url.Any help would be great.

Ok I understand what your saying now. If you look at the php spec for urlencode here:

In example #2, you will see they use urlencode just on the value part of the get param. If you wanted to go this route you could do something along the lines of:

$encoded_url = "";
$url = "google.com?id=3 &test=y()&display=y";
$params = explode("?",$url);
$encoded_url .= $params[0]."?";
$param_array = explode("&",$params[1]);
foreach($param_array as $param){
	$pair = explode("=",$param);
	$encoded_url .= $pair[0]."=".urlencode($pair[1])."&";
print $encoded_url;