A Neat Trick for Clickbank Sellers - Autofill the Country Field

Discussion in 'ClickBank' started by Owl, Feb 3, 2009.

  1. #1
    This is for people selling their own products on Clickbank, not for resellers of someone else's product as an affiliate.

    I noticed that my Clickbank payment page auto-detected my country (Australia) for the currency, but not for the location field. I couldn't see any way of changing this inside clickbank, but I noticed there is an option to pass an explicit country to the page as a form variable.

    So I did a google search and found a PHP script to detect the viewers country from their IP.

    This is the code, it will work if you have a PHP sales page (like I did), or if you have a straight HTML page just rename as .php (assuming PHP is enabled on your web host).

                         
    <?php 
    
    function countryCityFromIP($ipAddr)
    {
    //function to find <strong class="highlight">country</strong> and city from <strong class="highlight">IP</strong> <strong class="highlight">address</strong>
    //Developed by Roshan Bhattarai htp://roshanbh.com.np
    
    //verify the <strong class="highlight">IP</strong> <strong class="highlight">address</strong> for the
    ip2long($ipAddr)== -1 || ip2long($ipAddr) === false ? trigger_error("Invalid IP", E_USER_ERROR) : "";
    $ipDetail=array(); //initialize a blank array
    
    //get the XML result from hostip.info
    $xml = file_get_contents("htp://api.hostip.info/?ip=".$ipAddr);
    
    //get the city name inside the node <gml:name> and </gml:name>
    preg_match("@<Hostip>(\s)*<gml:name>(.*?)</gml:name>@si",$xml,$match);
    
    //assing the city name to the array
    $ipDetail['city']=$match[2]; 
    
    //get the <strong class="highlight">country</strong> name inside the node <countryName> and </countryName>
    preg_match("@<countryName>(.*?)</countryName>@si",$xml,$matches);
    
    //assign the <strong class="highlight">country</strong> name to the $ipDetail array
    $ipDetail['country']=$matches[1];
    
    //get the <strong class="highlight">country</strong> name inside the node <countryName> and </countryName>
    preg_match("@<countryAbbrev>(.*?)</countryAbbrev>@si",$xml,$cc_match);
    $ipDetail['country_code']=$cc_match[1]; //assing the <strong class="highlight">country</strong> code to array
    
    //return the array containing city, <strong class="highlight">country</strong> and <strong class="highlight">country</strong> code
    return $ipDetail;
    }
    
    $ip=$_SERVER['REMOTE_ADDR']; 
    
    $country_array =  countryCityFromIP($ip);
    
    // var_dump ($country_array);
    // echo ('</p><p>' . $country_array["country_code"]);
    
    ?>              
                                
     
    Code (markup):
    Then in the form that directs to CB,

     <input type="hidden" name="country" value="<?php echo $country_array["country_code"]; ?>">
    
    Code (markup):
    Or, if you are using a straight hyperlink (rather than a FORM ACTION= to direct to CB), then instead of the above <input> field, you can append the country value right onto the url with

    <A HREF="htp://1.yournickname.pay.clickbank.net/?country=<?php echo $country_array["country_code"]; ?> ">
    Code (markup):
    A nice touch for the buyer, for only 5 mins of effort

    IMPORTANT NOTE - i renamed all the occurrences of http to htp since I cant post live links yet, you need to change htp to http in three places above for the script to work
     
    Owl, Feb 3, 2009 IP