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

Simple PHP Question

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

  1. kickapooh

    kickapooh Regular Member

    Joined:
    Apr 16, 2010
    Messages:
    431
    Likes Received:
    845
    Hi. I came across a PHP GEO Targeting script that has been modified to randomly pick a URL to redirect people from certain countries to.
    The problem I am having is it is redirecting them to the URLs it picks randomly in an iFrame.
    I was wanting to know how to take out the iFrame and just have it redirect them normally.
    I'm awful at PHP so I figured I would post it up here to see if anyone would show me how to do it.
    I think the line that needs to be modified is: echo "<iframe src='$destination_list[$key]' width='100%' height='100%' frameborder='0'>";

    Below is the complete scipt. Thanks in advance. :D

    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''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.URL-TO-SEND-TRAFFIC-FROM-ABOVE-COUNTRIES-TO.com')
        ;}
        
         else
        
        {
        
    $destination_list = array(
        
    'http://www.URLS-TO-SEND-US-TRAFFIC-TO-1.com',
        
    'http://www.URLS-TO-SEND-CA-TRAFFIC-TO-2.com',
        
    'http://www.URLS-TO-SEND-UK-TRAFFIC-TO-3.com',
        
    'http://www.URLS-TO-SEND-AU-TRAFFIC-TO-4.com'
        
    );

        
    $key rand(0count($destination_list) - 1);

        echo 
    "<iframe src='$destination_list[$key]' width='100%' height='100%' frameborder='0'>";
        exit();
        }  
         
    ?>
     
  2. seikzeko

    seikzeko Newbie

    Joined:
    Mar 13, 2012
    Messages:
    5
    Likes Received:
    0
    replace that iframe code with this

    header('Location: $destination_list[$key]');

    thats about it
     
  3. kickapooh

    kickapooh Regular Member

    Joined:
    Apr 16, 2010
    Messages:
    431
    Likes Received:
    845
    Hmm tried it, not working... Any other ideas?
     
  4. Zapdos

    Zapdos Power Member

    Joined:
    Oct 22, 2011
    Messages:
    597
    Likes Received:
    708
    Location:
    Eastern North Carolina
    Reformatted it cause it hurt my soul lol

    Code:
    <?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', '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.URL-TO-SEND-TRAFFIC-FROM-ABOVE-COUNTRIES-TO.com');
        } 
        else {
            $destination_list = array(
                'http://www.URLS-TO-SEND-US-TRAFFIC-TO-1.com',
                'http://www.URLS-TO-SEND-CA-TRAFFIC-TO-2.com',
                'http://www.URLS-TO-SEND-UK-TRAFFIC-TO-3.com',
                'http://www.URLS-TO-SEND-AU-TRAFFIC-TO-4.com'
            );
    
            $key = rand(0, count($destination_list) - 1);
            
            header ('Location: '. $destination_list[$key] .'');
            exit();
        }
    ?>
     
    • Thanks Thanks x 1
  5. kickapooh

    kickapooh Regular Member

    Joined:
    Apr 16, 2010
    Messages:
    431
    Likes Received:
    845
    Worked. Thank you VERY much!!!