GEO targeting php and hostip

6 replies
Hello

I am trying to show/geo target javascript affiliate links for certian countries that my visitors to my site are from.

I have doing a little research on google and have found a few script but for some reason they do not work.

I know about the geoip database from maxmind but I am looking for a remote solution as the geoip database is said to be a heavy strain on servers if you get a lot of visitors. I am hosted on a shared server so I do not want to get my account suspended for over working the server. Also I have a few sites that will use this idea.

This is a script I found whilst googling and all it does is give me an error.

Code:
<?php 
$ip = $_SERVER [ 'REMOTE_ADDR' ]; 
$country = file_get_contents ( 'http://api.hostip.info/country.php?ip=' . $ip ); 
if ( $country == "US" ) { 
echo "<American-English Ringtone Ad Tag>" ; } 
elseif ( $country == "AU" OR $country == "UK" OR $country == "IE" ) { 
echo "<British-English Ringtone Ad Tag>" ; } 
else { 
echo "<YPN Ad Tag>" ; } 
?>
This is the error it gives me:-

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/username/public_html/webaddress.co.uk/test/test.php on line 7
For some reason it will not show the javascript generated affiliate links it just throws that error up.

I am using the hostip service.

Any advice would be of great help.

Thanks in advance.
#geo #hostip #php #targeting
  • Profile picture of the author pbarnhart
    Use maxmind's free javascript tool - much less messy. See MaxMind - MaxMind Javascript Web Service
    {{ DiscussionBoard.errors[2423439].message }}
    • Profile picture of the author webmasteruk
      A javascript option would be great but I do not know javascript.

      I would like to know please how would I use maxmind's free javascript option to show different ads for different countries.

      Example
      Display UK ad for uk visitors

      Display US ad for American visitors

      Display AU ads for australia visitors

      Any advice would be great.

      Thank you all in advance.
      {{ DiscussionBoard.errors[2424704].message }}
      • Profile picture of the author mojojuju
        Originally Posted by webmasteruk View Post

        A javascript option would be great but I do not know javascript.

        I would like to know please how would I use maxmind's free javascript option to show different ads for different countries.

        Example
        Display UK ad for uk visitors

        Display US ad for American visitors

        Display AU ads for australia visitors

        Any advice would be great.

        Thank you all in advance.
        Here's an easy way to do it:

        HTML Code:
        <html>
        <body>
        <script language="JavaScript" src="http://j.maxmind.com/app/country.js"></script>
        
        <script type="text/javascript">
        
        var cunt = geoip_country_code();
        
        if (cunt == "US")
        {
        document.write("Here is an offer for the United States");
        }
        
        else if (cunt == "UK")
        {
        document.write("It seems you are from the UK. I have just what you need.");
        }
        
        else if (cunt == "AU")
        {
        document.write("Here is an ad for australia visitors.");
        }
        
        else
        {
        document.write("I have no idea where you live. Want to buy some stuff though?");
        }
        </script>
        
        
        </body>
        </html>
        You've mentioned though that you thought the PHP API would put to much strain on your shared hosting account. But have you tried it? You might find that it doesn't require much resources at all.
        Signature

        :)

        {{ DiscussionBoard.errors[2425478].message }}
        • Profile picture of the author webmasteruk
          Mojo thank you for your help and an excerlent post.

          For some reason though when I paste the javascript ad code between:-

          document.write("It seems you are from the UK. I have just what you need.");
          It throws up an error.
          {{ DiscussionBoard.errors[2426233].message }}
          • Profile picture of the author mojojuju
            You've probably got some characters that need to be escaped.
            Signature

            :)

            {{ DiscussionBoard.errors[2426861].message }}
        • Profile picture of the author josh1az
          Originally Posted by mojojuju View Post

          Here's an easy way to do it:

          HTML Code:
          <html>
          <body>
          <script language="JavaScript" src="http://j.maxmind.com/app/country.js"></script>
          
          <script type="text/javascript">
          
          var cunt = geoip_country_code();
          
          if (cunt == "US")
          {
          document.write("Here is an offer for the United States");
          }
          
          else if (cunt == "UK")
          {
          document.write("It seems you are from the UK. I have just what you need.");
          }
          
          else if (cunt == "AU")
          {
          document.write("Here is an ad for australia visitors.");
          }
          
          else
          {
          document.write("I have no idea where you live. Want to buy some stuff though?");
          }
          </script>
          
          
          </body>
          </html>
          You've mentioned though that you thought the PHP API would put to much strain on your shared hosting account. But have you tried it? You might find that it doesn't require much resources at all.
          Hi

          this is good and works , but is there a way to have two opitons for each country


          so lets say someone see my website site in usa, i could have two options for that person the view , "you can buy here" with a us flag beside it, or "you can not buy here" with a us flag next to it , depending on what country they are from

          is this possible

          thx
          {{ DiscussionBoard.errors[9565274].message }}

Trending Topics