Jump to content

Cloak and Track a Link when using a variable url


vistavision

Recommended Posts

Hi everybody,

 

I want to cloak my affiliate links or mask it so it looks like a pretty url. Also if possible, I want to track the clicked link with Google Analytics so I think I need a page where I can log the click.

 

I found lots of information but not for the situation I have. I get my links from my database like this:

echo '<a href="'.$info['url'].'">the link</a>';

How can I accomplish this? So I need a url like www.mydomain.com/click and when a user click on the link the get a new page with a tracking code and a redirect script to the right url.

 

Thanks so much for the help!

 

Kind regards,

Mark

Link to comment
Share on other sites

Let's assume your links are stored in a table with an ID, the URL and a Text description. You can create your links like this:

 

echo "<a href='affiliate.php?id={$row['id']}'>{$row['text']}</a>';

 

Then create a page for affiliate.php. On that page you would take the ID passed on the query string and run a query to get the URL. Then you can do whatever logging of the click that you want to perform. Lastly, you would use a header() function to redirect the user to the URL.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.