phpL Posted January 28, 2009 Share Posted January 28, 2009 Hi, Iam a phpNewbie, but I want to learn. I have tried hours in search of the ultimate code for redirecting affiliate links. I also search the forums but no answer to my question. For explanation purposes, Ill use a simplification of my problem: I have a affliliate link that looks like this: http://affliliatecompany.com/c/?ab=1234&cd=products/1/2&ef= I use a file called 'bye.php' and I link to the affiliate link as the following: http://www.mysite.com/bye.php?webshop=http://affliliatecompany.com/c/?ab=1234&cd=products/1/2&ef= I have a script that grabs (GET) the url (after webshop): <?php $u=htmlspecialchars($_GET['webshop']."&".$_GET['ab']."&".$_GET['cd']."&".$_GET['ef']); ?> Then I use an echo in the meta refresh: <?php echo($u); ?> I have 2 problems: 1. My affiliatecompany says that I have to send the url encode to make this work, but how? <?php echo(rawurlencode($u)); ?> //something like this leaves url full of hexicode %2F etc 2. $_GET['ef'] is always empty but if so, it will not print so I use instead the following? <?php $u=htmlspecialchars($_GET['webshop']."&".$_GET['ab']."&".$_GET['cd']."&ef=); ?> I hope someone can provide me with some knowledge on how to make this work :-\ Thank you in advance! Link to comment https://forums.phpfreaks.com/topic/142783-how-to-encode-url-and-then-redirect-affiliate-link/ Share on other sites More sharing options...
phpL Posted January 29, 2009 Author Share Posted January 29, 2009 Maybe a simplification of my question is: How do I redirect an affiliated url like below (encoded)? http://affliliatecompany.com/c/?ab=1234&cd=products/1/2&ef= Link to comment https://forums.phpfreaks.com/topic/142783-how-to-encode-url-and-then-redirect-affiliate-link/#findComment-749528 Share on other sites More sharing options...
tran_dinh_ba Posted January 29, 2009 Share Posted January 29, 2009 You can use: urlencode($u) Hope this helps Link to comment https://forums.phpfreaks.com/topic/142783-how-to-encode-url-and-then-redirect-affiliate-link/#findComment-749540 Share on other sites More sharing options...
milesap Posted January 29, 2009 Share Posted January 29, 2009 $link = urlencode($link); header('Location: $link'); Ensure there is no white space before the header redirect or you'll get an error. Link to comment https://forums.phpfreaks.com/topic/142783-how-to-encode-url-and-then-redirect-affiliate-link/#findComment-749750 Share on other sites More sharing options...
phpL Posted January 30, 2009 Author Share Posted January 30, 2009 @tran_dinh_ba: When I urlencode the url will show with hexcode, that doesn't work. Altough the affiliate company suggested to encode the url before it is sent, but I don't know why it should be in the first place... @milesap: If I use your code it will show: http://www.mysite.com/$link I use the code below: <?php $u=htmlspecialchars($_GET['ab']."&".$_GET['cd']."&ef="); $link = urlencode($u); header('Location: $link'); ?> Is the following possible? <?php header("Refresh:4; URL='".urlencode($u)."'") ?> Link to comment https://forums.phpfreaks.com/topic/142783-how-to-encode-url-and-then-redirect-affiliate-link/#findComment-750331 Share on other sites More sharing options...
corbin Posted January 30, 2009 Share Posted January 30, 2009 Short HTTP protocol tutorial: GET params are separated by & and go in key=val pairs. Therefore, any = needs to be escaped as well as any &. So, if you want to append anything that has a & or = in it to a GET string, you must urlencode() it. If you are redirecting the client somewhere or something, but not passing it as a parameter, you do not need to urlencode it. Link to comment https://forums.phpfreaks.com/topic/142783-how-to-encode-url-and-then-redirect-affiliate-link/#findComment-750333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.