urls with vars in query string

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
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

urls with vars in query string

Post by php3ch0 »

I am writing a script to track pay per click and affiliate links from banners, adwords etc.

When the user clicks the links then it goes to this tracking script and stores the relevent data so that we can run reports on it. Then it forwards to the correct URL.

The problem is that the data and the url are provided by a third party who provide it in this sort of format:

part1:

should redirect to:
part2:


the bit in bold is causing the problems. Because of the extra & it is breaking the rest of the query string. The problem being becuase we cannot have any control over the url that is provided in part 1 nor do we have any control over the order of the URL variables. We also cannot do without the other vars as they are used as part of the tracking process.

Is there a way that we can get $_GET['redirect'] to be the correct part?
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: urls with vars in query string

Post by Ziq »

You can use rawurlencode() and rawurldecode() php function.

Code: Select all

 
<?
//...
$redirect_url = "http://www.somehost.com/page.php?a=2";
echo rawurlencode($redirect_url);
echo rawurldecode($_GET['redirect_url']);
//...
?>
 
Or you can storage redirect_url in database (or somewhere else) and use url_id.
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

Re: urls with vars in query string

Post by php3ch0 »

thanks for that will give it a try
Post Reply