1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need a simple PHP script edit

Discussion in 'PHP & Perl' started by kickapooh, May 23, 2012.

  1. kickapooh

    kickapooh Regular Member

    Joined:
    Apr 16, 2010
    Messages:
    431
    Likes Received:
    844
    I'm using a Geo Targeting script that was shared on another board a while back. I've had some changes made to it so it rotates the Tier1 URLs and splits my AU, CA, UK, US traffic up between 2 separate affiliate links.

    What I would like to do is also split up my Tier2 (foreign) traffic up the same way so I can send it to a couple different programs as well. I'm basically wanting to have 2 URLs for Tier2 traffic too, then have it alternate the URLs for each visitor. I'd like to give 50% of my foreign traffic to one link and the other 50% to another (just like the lower part of the code does)

    Would any PHP coders mind having a look at it and showing me the best way to accomplish this?
    Thanks.

    PHP:
    <?php
        
        $geo 
    unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR']));
        
    $countryCode $geo['geoplugin_countryCode'];

        
    $a=array('AD''AE''AF''AG''AI''AL''AM''AN''AO''AQ''AR''AS''AT''AW''AX''AZ''BA''BB''BD''BE''BF''BG''BH''BI''BJ''BM''BN''BO''BR''BS''BT''BV''BW''BY''BZ''CC''CD''CF''CG''CH''CI''CK''CL''CM''CN''CO''CR''CS''CU''CV''CX''CY''CZ''DE''DJ''DK''DM''DO''DZ''EC''EE''EG''EH''ER''ES''ET''FI''FJ''FK''FM''FO''FR''FX''GA''GB''GD''GE''GF''GH''GI''GL''GM''GN''GP''GQ''GR''GS''GT''GU''GW''GY''HK''HM''HN''HR''HT''HU''ID''IE''IL''IN''IO''IQ''IR''IS''IT''JM''JO''JP''KE''KG''KH''KI''KM''KN''KP''KR''KW''KY''KZ''LA''LB''LC''LI''LK''LR''LS''LT''LU''LV''LY''MA''MC''MD''MG''MH''MK''ML''MM''MN''MO''MP''MQ''MR''MS''MT''MU''MV''MW''MX''MY''MZ''NA''NC''NE''NF''NG''NI''NL''NO''NP''NR''NU''NZ''OM''PA''PE''PF''PG''PH''PK''PL''PM''PN''PS''PT''PW''PY''QA''RE''RO''RU''RW''SA''SB''SC''SD''SE''SG''SH''SI''SJ''SK''SL''SM''SN''SO''SR''ST''SU''SV''SY''SZ''TC''TD''TF''TG''TH''TJ''TK''TL''TM''TN''TO''TP''TR''TT''TV''TW''TZ''UA''UG''UY''UZ''VA''VC''VE''VN''VU''WF''WS''YE''YT''YU''ZA''ZM''ZR''ZW'); 

        if (
    in_array($countryCode$a)) {
            
    header ('Location: http://www.Tier2-Affiliate-Link.com');
        } 
        else {
            
    $destination_list = array(
                
    'http://www.Tier1-Affiliate-Link-1.com',
                
    'http://www.Tier1-Affiliate-Link-2.com'
            
    );

            
    $key rand(0count($destination_list) - 1);
            
            
    header ('Location: '$destination_list[$key] .'');
            exit();
        }
    ?>
     
  2. tripper_john_md

    tripper_john_md Newbie

    Joined:
    Feb 21, 2011
    Messages:
    40
    Likes Received:
    35
    Location:
    Southern Germany
    So - did you try to copy the lower part of the code and replace the current tier2-redirection? Because that's all you have to do.
     
  3. wickedguy

    wickedguy Supreme Member

    Joined:
    Jul 22, 2009
    Messages:
    1,402
    Likes Received:
    1,379
    Location:
    BHW--> South Africa
    Home Page:
    I think this is what you want :)

     
    • Thanks Thanks x 1
  4. jennym

    jennym Junior Member

    Joined:
    Sep 26, 2008
    Messages:
    176
    Likes Received:
    89
    I haven't tried it, but I just copied the second part. let me know if it works

    PHP:
    <?php
        
        $geo 
    unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR']));
        
    $countryCode $geo['geoplugin_countryCode'];

        
    $a=array('AD''AE''AF''AG''AI''AL''AM''AN''AO''AQ''AR''AS''AT''AW''AX''AZ''BA''BB''BD''BE''BF''BG''BH''BI''BJ''BM''BN''BO''BR''BS''BT''BV''BW''BY''BZ''CC''CD''CF''CG''CH''CI''CK''CL''CM''CN''CO''CR''CS''CU''CV''CX''CY''CZ''DE''DJ''DK''DM''DO''DZ''EC''EE''EG''EH''ER''ES''ET''FI''FJ''FK''FM''FO''FR''FX''GA''GB''GD''GE''GF''GH''GI''GL''GM''GN''GP''GQ''GR''GS''GT''GU''GW''GY''HK''HM''HN''HR''HT''HU''ID''IE''IL''IN''IO''IQ''IR''IS''IT''JM''JO''JP''KE''KG''KH''KI''KM''KN''KP''KR''KW''KY''KZ''LA''LB''LC''LI''LK''LR''LS''LT''LU''LV''LY''MA''MC''MD''MG''MH''MK''ML''MM''MN''MO''MP''MQ''MR''MS''MT''MU''MV''MW''MX''MY''MZ''NA''NC''NE''NF''NG''NI''NL''NO''NP''NR''NU''NZ''OM''PA''PE''PF''PG''PH''PK''PL''PM''PN''PS''PT''PW''PY''QA''RE''RO''RU''RW''SA''SB''SC''SD''SE''SG''SH''SI''SJ''SK''SL''SM''SN''SO''SR''ST''SU''SV''SY''SZ''TC''TD''TF''TG''TH''TJ''TK''TL''TM''TN''TO''TP''TR''TT''TV''TW''TZ''UA''UG''UY''UZ''VA''VC''VE''VN''VU''WF''WS''YE''YT''YU''ZA''ZM''ZR''ZW'); 

        if (
    in_array($countryCode$a)) {
                
    $destination_list2 = array(
                
    'http://www.Tier2-Affiliate-Link-1.com',
                
    'http://www.Tier2-Affiliate-Link-2.com'
            
    );
            
    $key rand(0count($destination_list2) - 1);
            
            
    header ('Location: '$destination_list2[$key] .'');        
        } 
        else {
            
    $destination_list = array(
                
    'http://www.Tier1-Affiliate-Link-1.com',
                
    'http://www.Tier1-Affiliate-Link-2.com'
            
    );

            
    $key rand(0count($destination_list) - 1);
            
            
    header ('Location: '$destination_list[$key] .'');
            exit();
        }
    ?> 
     
    • Thanks Thanks x 1
  5. confined

    confined Regular Member

    Joined:
    Jan 4, 2009
    Messages:
    216
    Likes Received:
    91
    what wickedguy and jennym posted should work.

    A more important issue is your first line, how many uniques per day will this script get?

    Sending an external request to a site outside of your control is bad practice. If that site is slow or goes offline your visitors will time out and close your site before it gets a chance to throw an error.

    A simple way would be to set up your site where this script is hosted at cloudflare and use their built in country code variables.

    so the first two lines could be changed to

    PHP:
    $countryCode  $_SERVER['HTTP_CF_IPCOUNTRY'];
    that one line if you utilize cloudflare for your website. Just a heads up
     
    • Thanks Thanks x 1