$variable = "boo boo";
print "Content-type: text/html\n";
print "Location:http://hithere.com?$variable";
Works fine in Safari and IE6/Win.but in Mac IE5 the browser location bar reads "http://hithere.com?boo%2520boo".
No problem, I thought, I'll just change the space to a %20:
$variable =~ s/ /%20/;
No luck, same prablem. Substituting \x20 for the %20 didn't help either. I tried various flavors of pack, but I was just guessing since I really don't understand what I'm doing there.
How the heck can I call example.com?boo%20boo?
Thanks for your help. Oh, by the way, the variable really, really has to have a space in it. That would be an easy workaround if I could use strings without spaces, but I can't. :(
My php is pretty basic, so I may have this wrong, but I think you need to use urlencode() and urldecode() - just urlencode your variable before putting it in the query string, and urldecode it before using it on the target page,
The CGI below mimics the problem you're having.
$\="\n";
my $var = "space space";
encode();
if ($ENV{'HTTP_USER_AGENT'}=~/Mozilla\/4.0 \(compatible; MSIE 5.\d+;/) {
encode(); # Oops, encoded too many
}
print "Content-Type: text/html; charset=ISO-8859-1";
print "Location:http://localhost/index.html?$var\n";
sub encode {
$var =~s/\W/ sprintf("%s%x", '%', ord($&)) /ge;
}