Page 1 of 1

url redirection problem on urls with & character

Posted: Sun May 04, 2003 7:56 am
by Ozz
I'm using a frame redirector and click counter system for outside linking.
Urls like:
http://www.mysite.com/framed.php?out=ht ... ersite.com
Everything is working fine.
The only problem is urls with amp (&) characters. Like:
http://www.mysite.com/framed.php?out=ht ... section=87
In this example url; the part after & character can not be included at the url which needed on the framed.php.
I mean the "out" variable takes http://www.othersite.com?id=4398 value and linking like that and of course it comes with a 404 page on other site.
How can I use & character in this situation?
It can be replaced with another character?

Posted: Sun May 04, 2003 8:05 am
by volka

yes

Posted: Sun May 04, 2003 8:15 am
by Ozz
But urls gettin from the database not hand coded.
How can I convert and replace to encoded url?

Posted: Sun May 04, 2003 8:21 am
by volka

Posted: Sun May 04, 2003 11:31 am
by Ozz
Thanks volka
I found a simple solution:
$url = str_replace("&", "%26", $url);

I hate to be a newbie
:)

Posted: Sun May 04, 2003 11:45 am
by volka
you really should use

Code: Select all

$url = urlencode($url);
since there are other characters that might cause trouble.

Posted: Sun May 04, 2003 12:18 pm
by Ozz
Yes I added urlencode too.
Thanks

Posted: Sun May 04, 2003 5:17 pm
by volka
too? no, instead of that str_replace ;)