Results 1 to 9 of 9
  1. #1
    Member lschofield's Avatar
    Join Date
    April 11th, 2007
    Location
    Chicago, IL
    Posts
    137
    Best way to cloak different links for the same merchant
    I've spent the majority of 2 days now searching here for the best way to cloak different links for merchants.

    I think housing them in a mySQL database is the way to go, particularly for time sensitive offers and coupons (then you can simply query your table on the 'finish' or 'end' field, or whatever you want to call the expiry date for your link and update it or delete it from there. Also, I'm sure a relational database would be ideal for housing multiple merchants with multiple links.

    I've read about creating a new folder to house PHP scripts that contain the actual affiliate link and then pointing the link in your html page towards the relevant PHP script. I like to link deep though in my pages, and rarely use a generic homepage affiliate link, so this could get REAL big real quick. However, this may be a good solution for my 88x31s...

    I've set up a table in mySQL (I can access this through PHPmyAdmin) and have no probs entering records (I'm using 7 fields - id, merchant, name, link, click, start, and end). I've set the ID to autofill and use it as a primary key. Merchant is self-explanatory, I'd like to have this to filter based on merchant. Name is how I can visually identify if this is for a specific product and what type of link, etc... Link is where I contain my coded affiliate link itself, click will be used for tracking and incremented when the below script is called. Start and end will be dates: start being the date posted to the site, and end being the link's expiry date.

    I found this script here (submitted to this forum by BluesX) where you can enter the id of the mySQL record containing the link you want to use, and thus have your PHP script point to the correct link in your mySQL table. I'm envisioning one static PHP script, called with various arguments that point to different records in mySQL with the appropriate link, arguments being the records ids.
    for beginners, here is a small php code to hide your affiliate links (inside the mysql)

    <?php
    $dblink = mysql_connect("localhost","mysql_user", "mysql_password");

    $result = mysql_db_query("dbname","select * from tablename where id='$sku'");
    $row = mysql_fetch_array($result);
    $link = $row["link"];
    // mysql_query("update tablename set click=click+1 where id='$sku'"); // increase click count to track your clicks
    header("Location: $link"); // send an http header with your affiliate link
    mysql_free_result($result);
    mysql_close($dblink);
    ?>

    so in place of your affiliate link, you use "script.php?sku=NNN"

    so you'll need to create a mysql table with 3 fields, id is primary/unique, link for links and click for tracking click count

    This much is free! If you want a custom solution, call me..
    I'm thinking I'd update "local_host", "mySQL_user", "mySQL_password" to log in to mySQL and access the database through the $dblink. I'd update "dbname" and "tablename" for the $result (leaving sku alone as the argument will be passed from NNN when the script is called. ) In the $link, I'll leave "link" so that will just refer to the appropriate column. Finally, I'd be sure to customise "tablename" where you increase the click count. So - it looks important that your table contains fields named exactly "id", "link", and "click", and that click is set to an integer data-type. I'd also create the above PHP code as a .php file in my root directory, or maybe the directory I'm housing the redirects for my 88x31s (as described above), and then call the PHP code in my html pages with "script.php?sku=NNN" where NNN is the ID for the link's record.

    I guess I answered alot of my questions throughout the creation of this post (I tend to answer myself when I write a question and thoroughly research it, and word it logically), but will post it anyways in case it might benefit another newbie, or also in case anyone sees any major errors to my plan, or improvements to it, etc...

    While putting this together for my site, though, I just got a different question. That first line of code will have some pretty sensitive information. I wouldn't want just anyone to be able to view that.... Anyone have any good ideas on how to protect this file? Obviously I should'nt put it in the root directory...
    Last edited by lschofield; April 27th, 2007 at 02:02 PM.
    [IMG]http://www.centsible.net/images/centsible28x196.bmp[/IMG]
    Making Cents of the Internet

  2. #2
    ABW Ambassador
    Join Date
    November 25th, 2005
    Posts
    639
    Hi lschofield,

    I don't want to hijack your thread but this is on the same topic: A funny thing happened a couple of weeks ago...

    I was replacing some dead links on a static page that was enjoying an upsurge in traffic. Feeling particularly lazy, I opted to use the CJ product links that inlcude an image and text within a form. This posts the information as form fields instead of using the querystring. Wham, the next day, I see more sales than I have seen in many weeks! Things have been pretty steady ever since. I wonder if the form is another viable method of cloaking a link?

    Any comments?

  3. #3
    Member lschofield's Avatar
    Join Date
    April 11th, 2007
    Location
    Chicago, IL
    Posts
    137
    No probs on the hijacking CanadianDave. Interesting - no matter what is happening I wouldn't fix it... I use those product forms from CJ on a page that is really bad still - I haven't done much with it and don't promote it yet, so I'll see what happens with that once I start sending traffic there and we can compare results...

    Back to the bit of code submitted by BluesX, I couldn't connect to my database when I tried it. I added a SSI to accomplish this - saving this as conn.php in the same directory as the other script... (obviously I've updated the relevant areas...)

    Code:
    <?php
    $strServer="66.9.65.200"; // Server IP Address 'or' Name
    $strDatabase="database name"; // Database Name
    $strUser="root"; // User ID
    $strPwd="pwd"; // Password
    ?>
    So, now my script to call the links from the mySQL dbase looks like this

    <?php
    include(\"conn.php\")
    $strDB=mysql_connect($strServer,$struser,$strPwd);
    $database=mysql_select_db(\"$strDatabase\",$strDB);

    $result = mysql_db_query(centsible_net,\"select * from links where id=\'$sku\'\");
    $row = mysql_fetch_array($result);
    $link = $row[\"link\"];
    // mysql_query(\"update links set click=click+1 where id=\'$sku\'\"); // increase click count to track your clicks
    header(\"Location: $link\"); // send an http header with your affiliate link
    mysql_free_result($result);
    mysql_close($strDB);

    ?>
    and I'm getting an error still (although this time its not about the connection). Here's what the error is if anyone would like to help debug it.

    Parse error: syntax error, unexpected T_VARIABLE in /export/home/ce/centsible.net/public_html/visit/script.php on line 3
    [IMG]http://www.centsible.net/images/centsible28x196.bmp[/IMG]
    Making Cents of the Internet

  4. #4
    Newbie
    Join Date
    April 27th, 2007
    Posts
    16
    Try removing the slashes. So

    $database=mysql_select_db(\"$strDatabase\",$strDB);

    is just:

    $database=mysql_select_db("$strDatabase",$strDB);

    Or you could just try this instead (The second variable is optional):

    $database=mysql_select_db($strDatabase);

  5. #5
    Member lschofield's Avatar
    Join Date
    April 11th, 2007
    Location
    Chicago, IL
    Posts
    137
    Quote Originally Posted by Colossor
    Try removing the slashes. So

    $database=mysql_select_db(\"$strDatabase\",$strDB);

    is just:

    $database=mysql_select_db("$strDatabase",$strDB);

    Or you could just try this instead (The second variable is optional):

    $database=mysql_select_db($strDatabase);
    Thanks for the suggestion Collosor. I've been earnestly debugging this (and learning PHP at the same time!).

    Those unexpected T_variables were the comments. I've taken those out and now get down to line 7 in my debugging efforts...

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user '******'@'jupiter.catalog.com' (using password: YES) in /export/home/ce/centsible.net/public_html/visit/script.php on line 7
    Cannot connect to DB!
    Just got off the phone with the people at catalog.com to ensure I was using the correct server, I was. Not sure how to proceed now, but I'll keep working at it...

    Also, I've stopped using an include for the initial connection code and just put it all in my script code.

    Again, it worries me for this info to be available to everyone. I think a database of affiliate links would want to be off limits to possible pirates. Anyone know who to make scripts unaccessible to the general public? If not, how to safely connect to your db using your user name and password?
    [IMG]http://www.centsible.net/images/centsible28x196.bmp[/IMG]
    Making Cents of the Internet

  6. #6
    Full Member
    Join Date
    October 22nd, 2006
    Posts
    200
    Remenber to put a ; at the end of each line;

    include(\"conn.php\");

  7. #7
    Member lschofield's Avatar
    Join Date
    April 11th, 2007
    Location
    Chicago, IL
    Posts
    137
    Everything works perfect with creating separate PHP files for my 88x31 image links in order to cloak/redirect them with the following script

    Code:
    <?php 
      $url = \'type affiliate link here \'; 
      header(\"Location: $url\"); 
      exit();   
    ?>
    and then linking to my PHP script for the link, and following it with the tracking image and closure for the anchor. There is a problem with doing this for Performics links, and I did contact them regarding this. They have said they do allow for redirects through PHP, but have a problem where an error page is served for a while between when the link is created and when their servers actually recognize that link. The LS links I've redirected have worked fine.

    As far as the script to access links from a mySQL database, I'm stuck temporarily and debugging this (while I teach myself PHP through tutorials). The problem is with selecting the proper link in the array. I'm able to make the connection to my database and open it, selecting * from the table that I want to reference. I start getting failure though when specifiying the argument supplied in the calling link (i.e. - a href="url/visit/merchant.php?sku=nnn" where nnn is the unique identifier for that row")

    I've made a WHERE statement with the LIKE comparison operator and not had a problem. Its where I try to use the where id=\'$sku\' condition that my script fails. I tried replacing the = operator (thinking its used for assignment) with ==, but the script still failed. I've tried including the $sku variable in [] with no success either. Anybody have any ideas?

    When I get it working, I'll post my fix here.... And many thanks to anyone who can help!
    [IMG]http://www.centsible.net/images/centsible28x196.bmp[/IMG]
    Making Cents of the Internet

  8. #8
    Member lschofield's Avatar
    Join Date
    April 11th, 2007
    Location
    Chicago, IL
    Posts
    137
    Success at last!
    I know this post is a little old, and I don't mean to resurrect something that is irrelevant, but I said I'd post when I got my head around this, so here goes...

    A couple of quick notes:


    This works brilliantly with orange links from Performics particularly. I'm starting with my banner ads, will move ahead to coupons and other text later...

    I have a database with fields for: a unique ID, clicks, store name, type of promo, url, tracking image, alternate text, display image, image size, and expiration date.

    I make use of my base shtml, 2 different PHP files and an external MySQL database. One of the PHP files supplies the banner image to be displayed from my MySQL database, the other PHP increments my click tracking and cloaks my link.

    My base SHTML has an include to the 1st PHP file, and I specify which banner to use by including the record number as a query string in my include address. When that SHTML loads, it includes the PHP file and sends it a query string. The PHP file queries MySQL and returns the image to display for the banner ad, also echoing a link to my 2nd PHP file (once again, using a query string to reference the correct record). If clicked, the visitor is taken to my 2nd PHP script in a new window (via target=_blank), where the SKU is caught from the query string with _GET, the field tracking clicks is incremented by one, and the visitor is taken to the merchant with a header.

    Here is an example of the initial include:

    BTW, I keep my connection info a separate file so that if I switch servers, I only have to update it in one place. I then call this file at the start of all my connection scripts.

    Code:
    <!--#include virtual=\"/visit/promo.php?sku=1\" -->
    Which thus includes the results of the following PHP code
    Code:
    <?php
    
    include(\"dbinfo.inc.php\");
    $sku=$_GET[\'sku\'];
    mysql_connect(\"mysql.webhero.com\",$username,$password);
    @mysql_select_db($database) or die( \"Unable to select database\"); 
    
    $query=\"SELECT * FROM table WHERE offer_unique=$sku\";
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    
    mysql_close();
    
    $i=0;
    while ($i < $num) {
    $id=mysql_result($result,$i,\"unique\");
    $shop=mysql_result($result,$i,\"shop\");
    $deal=mysql_result($result,$i,\"deal\");
    $go=mysql_result($result,$i,\"go\");
    $text=mysql_result($result,$i,\"text\");
    $img=mysql_result($result,$i,\"img\");
    $dimension=mysql_result($result,$i,\"dimension\");
    $finish=mysql_result($result,$i,\"finish\");
    
    echo \"<a href=/visit/deal.php?sku=\" . $sku . \" target=&quot;_blank&quot;><img src=\" . $img . \"class=&quot;neat&quot; alt=\" . $text . \"></a><br>\";
    
    ++$i;
    } 
    
    ?>
    Now the banner stored in my MySQL database is displayed, and a link is given to a 2nd PHP file, with the same SKU as a query string.

    The second file includes this code:
    Code:
    <?php
    ob_start;
    include(\"dbinfo.inc.php\");
    $sku=$_GET[\'sku\'];
    mysql_connect(\"mysql.webhero.com\",$username,$password);
    @mysql_select_db($database) or die( \"Unable to select database\"); 
    
    $query=\"SELECT * FROM table WHERE unique=$sku\";
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    
    $i=0;
    while ($i < $num) {
    $id=mysql_result($result,$i,\"unique\");
    $visits=mysql_result($result,$i,\"visits\");
    $go=mysql_result($result,$i,\"go\");
    
    ++$i;
    } 
    
    header("Location: $go");
    mysql_query("UPDATE table SET visits=visits+1 where unique='$sku'");
    
    mysql_free_result($result);
    mysql_close();
    ob_end_flush();
    
    ?>
    The only problem I'm encountering now is with the header in the 2nd file. I'm getting a headers already sent message.... As you can see, I'm trying to manipulate this with my buffers, but haven't fixed it yet.

    Feedback?

    Has anyone witnessed any problems from a SQL injection? I know its an old trick, but aff marketing is so cut-throat it kinda scares me.
    [IMG]http://www.centsible.net/images/centsible28x196.bmp[/IMG]
    Making Cents of the Internet

  9. #9
    Member lschofield's Avatar
    Join Date
    April 11th, 2007
    Location
    Chicago, IL
    Posts
    137
    Quote Originally Posted by lschofield

    The only problem I'm encountering now is with the header in the 2nd file. I'm getting a headers already sent message.... As you can see, I'm trying to manipulate this with my buffers, but haven't fixed it yet.
    Fixed it, I just forgot the () at the end of my ob_start(); !!!

    I love this, and wish I would've spent more time on it at the start!
    [IMG]http://www.centsible.net/images/centsible28x196.bmp[/IMG]
    Making Cents of the Internet

  10. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Do you cloak your affiliate links?
    By johnnyAffiliate in forum Programming / Datafeeds / Tools
    Replies: 17
    Last Post: December 23rd, 2010, 01:36 PM
  2. How many people cloak links?
    By Core in forum Midnight Cafe'
    Replies: 2
    Last Post: March 12th, 2007, 11:11 AM
  3. How do I Cloak my SAS links?
    By ocs94 in forum ShareASale - SAS
    Replies: 18
    Last Post: July 20th, 2006, 01:04 PM
  4. Do you cloak your indie links?
    By Trying to Win in forum Programming / Datafeeds / Tools
    Replies: 0
    Last Post: April 8th, 2006, 01:04 PM
  5. how to cloak Linkshare links
    By prix in forum Rakuten LinkShare - LS
    Replies: 0
    Last Post: August 12th, 2005, 07:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •