how to set an affiliate click and cookie in external script

Discussion in 'aMember Pro v.4' started by customcodegeek, Feb 19, 2012.

  1. customcodegeek

    customcodegeek Member

    Joined:
    Feb 10, 2012
    Messages:
    40
    I have just about finished migrating all of my users/affiliates/commissions/payments and products over to Amember from digital access pass.

    all I need to do is intercept all the old affiliate links.

    I can detect the user id of the DAP user from the link vars and I can retrieve the Amember user from db using the additional field I added and set when I imported the users.

    now I am stuck on how to record the click and set a cookie.

    (I can record the click by manually like this after including /amember/bootstrap.php)
    Code:
    $query = Am_Di::getInstance()->db->query("INSERT INTO ?_aff_click
                SET
                aff_id=?d,
                time=?,
                banner_id=?d,
                remote_addr=?,
                referer=?
                ",
                $affiliate_id,
                date('Y-m-j H:M:i'),
                null,
                $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_REFERER']
                );
                $clickid = Am_Di::getInstance()->db->selectCell("SELECT LAST_INSERT_ID()");
    but that's not the best way I am sure!

    could you give me a pointer on how to record the click and set the cookie using Amember functions from the file I have placed in the same place as the old GO script that DAP uses? (this file is not part of Amember, it is external to any Amember plugins/modules)

    Once I have this in place, I will have fully moved from DAP -> Amember and would be happy to write a tutorial on the process
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    You can get an example in /amember/application/aff/controllers/GoController.php:
    PHP:
       $aff_click_id $this->getDi()->affClickTable->log($this->aff$this->banner);
                
    $this->getModule()->setCookie($this->aff$this->banner $this->banner null$aff_click_id);
  3. customcodegeek

    customcodegeek Member

    Joined:
    Feb 10, 2012
    Messages:
    40
    Thanks Alexander i already saw that but I need to do this in an external file so $this does not exist.

    How to initiate the proper class so I can use $this?
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    PHP:
    Am_Di::getInstance->affClickTable
    Am_Di
    ::getInstance->modules->get('aff')->setCookie
  5. customcodegeek

    customcodegeek Member

    Joined:
    Feb 10, 2012
    Messages:
    40
    thanks so much for your help Alexander. I managed to get it working so I can convert the old Digital Access Pass affiliate links in to Amember affiliate links.

    here's my code if anyone else comes searching for this

    PHP:
    <?php
        
    /** affiliate link converter .
        * goes from DAP to Amember by detecting the affiliate id of DAP users link and tries to match
        * to the dapid that was saved to the users in amember that were imported.
        *
        * example link http://toolstomakemoney.com/dap/a/?a=1&p=www.example.com/somepage.html
        */

        
    include_once "../../member/bootstrap.php";

        
    $a = isset($_GET['a']) ? $_GET['a'] : ""//a = DAP affiliate id
        
    $p = isset($_GET['p']) ? $_GET['p'] : "http://toolstomakemoney.com"// get DAP URL or default to main site
        
    if($a){
            
    // this is a DAP affiliate link, get AM user based on dapid (dapid is an additional sql field set when DAP users were imported)
            
    $affiliate_id Am_Di::getInstance()->db->selectCell("SELECT user_id FROM ?_user WHERE dapid = ? LIMIT 1",$a);
            if(
    $affiliate_id){
                
    // there is a AM user for this DAP user. load the user
                
    $aff Am_Di::getInstance()->userTable->load($affiliate_idfalse);
                
    // record the click and set the cookie
                
    $aff_click_id Am_Di::getInstance()->affClickTable->log($affnull);
                
    Am_Di::getInstance()->modules->get('aff')->setCookie($affnull$aff_click_id);
                
    // forward to the URL supplied
                
    header("Location: $p");
            }
        }
    ?>
    wpauto likes this.
  6. scott_wa1

    scott_wa1 aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    62
    That "anyone else" was me. I don't like bumping old threads but I had to say THANK YOU, this is exactly what I needed. I had a similar script for v3 but my client updated to v4 and I needed to re-create it. Works perfectly!

    Scott
  7. customcodegeek

    customcodegeek Member

    Joined:
    Feb 10, 2012
    Messages:
    40
    hey you're welcome, glad it helped someone (or "anyone") ;P

Share This Page