PDA

View Full Version : Problem with URL redirection



deanp27
10-16-2005, 12:16 AM
I am really getting desperate now. Hopefully someone will manage to help me on this. I have created a clck.php page that redirects the users when they click on the banner to the URL of the advert. The purpose of the extra page (clck.php) is to enable me to track the clicks and assign them to the members. Then I connect the clck.php with the front site of the website by giving the url the following format: http:www.mysite.com/clck.php?lnk=URL. When I put the mouse on the banner it shows the full link but when you actually click on the banner it doeasn't take all the link. For example if the link is
http://merchant.com&affid=xxx&refid=xxx&subaff=xxx it will only redirect you to : http://merchant.com&affid=xxx. It won't pick up the rest of the URL although when i put the mouse on the link it does show on the explorer bar on the bottom the full link. If I shorten the link lie: http://samplesite.com then it will pick up the site and redirect without any problem.

Here is the code.

The clck.php is:
<?php
include_once('./inc/default.inc');
$redir = $_GET['lnk'];
swomCreateClick("test", $redir);
header("Location:$redir");
?>

The relevant part from the default.inc is:

function swomCreateClick($username, $link)
{
global $MySQL_LinkID;
$merch_id = swomGetMerchantIDByURL($link);
$date = date("m/d/y");

if(!(mysql_query("INSERT INTO swomOpenClickList VALUES(NULL, '$username', '$merch_id', '$date', '0')")))
echo(mysql_error());
}

I am really lost. Does anyone have any clue??

Thanks in advance

Twey
10-16-2005, 11:01 AM
<?php
include_once('./inc/default.inc');
$redir = $_GET['lnk'];
swomCreateClick("test", $redir);
header("Location:$redir");
?>
Two problems: there should be a space between the header name and value, and unencoded ampersands (&) in the URL will confuse the server. To solve this problem, you should urlencode() the URL (something like Javascript's escape()).
Final code:

<?php
include_once('./inc/default.inc');
$redir = urlencode($_GET['lnk']);
swomCreateClick("test", $redir);
header("Location: $redir");
?>