Link Cloaking with PHP

smile66603's picture

I'm setting up my website so I can cloak my affiliate URLs, but have a PHP question.

On the redirect page, I'm using the code:

<?php
header( 'Location: http://www.yoursite.com?SID=' ) ;
?>

In the link that leads to the redirect page, I'm going to be passing a query string that will contain the keyword id and the search engine, but will I be able to append this to the end of the link as the value to the SID parameter? Since PHP is processed on the server, but query strings are something that show up in the address field of the browser, won't the redirect occur before it can read the query string?

Thanks
James

Also, In the link that

smile66603's picture

Also,

In the link that links to the redirect page, I'm passing these values with the code:

?keyword_id=<?php echo $_GET['keyword_id']?>&search_engine=<?php echo $_GET['search_engine'] ?>

On the redirect page, would this be the correct way to append the data to the SID?

&SID=<?php echo $_GET['keyword_id']?>." ". <?php echo $_GET['search_engine']?>

I would think this method might cause some problems, because the single quotes in the GET statement will probably cause problems with the single quotes around the

'Location: http://www.yoursite.com?SID='

The first single quote in the first GET statement would end the statement.

I'd really appreciate any help; I know enough PHP to be dangerous and just want to make sure my leads are tracked.

James

James, all that code gives

Barry_G's picture

James, all that code gives me a friggin headache man!

Just kidding (sort of)

Have you seen this older thread - http://www.quityourdayjob.com/node/1229

Hope this helps, good luck, and maybe you can help me get my head 'round all this php some day.

Hi James, Quick note - OMS

Jeremy Palmer's picture

Hi James,

Quick note - OMS was just released today. As a PPC Classroom customer you're entitled to a free upgrade. Let me know if you didn't get the e-mail that was sent out last night (I'm guessing you didn't). OMS handles this situation automagically with no mess. You don't have to insert a single line of PHP to use it.

Regarding your question:

Setup a tracking URL from your pay per click ad. Append tracking variables to the URL using querystring parameters.

http://www.MyAffSite.com/landing.php?keyword=MyKeyword&source=Google

Add this code to the top of your landing page (don't forget opening and closing php tags):


//create a variable to hold the values from your tracking url
$sub_id = $_GET['keyword'] . '-' . $_GET['source'];
//set cookie with tracking variables
setcookie("visitor_id", $sub_id);
//your cookie now contains the values from your querystring (keyword and source)

This code sets a cookie with the tracking variables from your PPC ad.

Now on your cloaked link page you can simply redirect the user with your affiliate link and cookie as the sub id value.

Add this code to your redirect file (include opening and closing php tags)


header("Location:http://www.MyAffLink.com/?sub_id={$_COOKIE['visitor_id']}");

That's it - a PHP tracking solution in just 4 lines of code ;)

Best,

Jeremy

Thanks for the info. Wish I

smile66603's picture

Thanks for the info. Wish I knew PHP a little better, but should be able to figure it out based on the info you gave.

In the last step, you have:

?sub_id={$_COOKIE['visitor_id']}");

Will CJ recognize sub_id= instead of SID=

I always thought you had to use SID and have it in all caps.

James

Sub ID is just a place

Jeremy Palmer's picture

Sub ID is just a place holder. You must use SID or sid for CJ. Each network is a little different - so I decided to make the code agnostic ;)

I just realized I probably

smile66603's picture

I just realized I probably should have put this post in the PHP section, but since it was about cloaking, I thought it might fit here.

Anyone with PHP knowledge feel free to join the discussion. I'm always anxious to learn more.

Since we're on a role, I've got just one last PHP question and then I promise I'll stop ;)

The code you gave me above worked great for cloaking, but now I'm working on a page with a form submit, instead of an affiliate, so I'm not going to be able to use that method. I still want to use the cookie method though, because it's a multi page site and I want the keyword and source data to follow the user around the site so they can submit the form from any page on the site. In the past, I've passed these values in the links to the other pages, but that makes the links so long and ugly. So I'll store the values in the cookie and then I'll pass these values with the form. My question is, since this is a different situation, am I using the cookie correctly so it will be passed. I know all the HTML is working, because I've been using it for some time, but I'm not too sure about the PHP

input type="hidden" name="SID" value="<?php echo $_COOKIE['visitor_id'];?>"

I tried it on one of the pages of my site and when I used the form to go to the merchant site, the SID info was blank, so I went back to my site and refreshed the page and submitted the form again and it worked that time. It only seems to work when I refresh the page and submit the form again.

Thanks for all the info, it's a huge help.
James

I don't think the

smile66603's picture

I don't think the cloaking/cookie method is working. I switched one of my websites over to use the cookies and now, none of those leads are tracking the SID info and in my CJ reports the SID information is showing up completely blank.

James

No one willing to respond?

smile66603's picture

No one willing to respond? LOL

This method only seems to work if you refresh the page before you click any links.

Just as a test, I used a cookie to store some text that is passed in the URL and then used PHP to display that text. When I first type in the URL and go to the page, the text isn't displayed, but if I click the refresh button on the browser, the text is displayed.

James

Syndicate content