url redirection problem on urls with & character

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ozz
Forum Commoner
Posts: 26
Joined: Wed Aug 21, 2002 11:47 pm

url redirection problem on urls with & character

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Ozz
Forum Commoner
Posts: 26
Joined: Wed Aug 21, 2002 11:47 pm

yes

Post by Ozz »

But urls gettin from the database not hand coded.
How can I convert and replace to encoded url?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Ozz
Forum Commoner
Posts: 26
Joined: Wed Aug 21, 2002 11:47 pm

Post by Ozz »

Thanks volka
I found a simple solution:
$url = str_replace("&", "%26", $url);

I hate to be a newbie
:)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you really should use

Code: Select all

$url = urlencode($url);
since there are other characters that might cause trouble.
Ozz
Forum Commoner
Posts: 26
Joined: Wed Aug 21, 2002 11:47 pm

Post by Ozz »

Yes I added urlencode too.
Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

too? no, instead of that str_replace ;)
Post Reply