Rotate Links Using Geoplugin

2020-05-03 12:19发布

I'm geoplugin.class to redirect CA users to a specific link.

Right now the code only allows me to redirect the user to 1 website. I would like to modify this code so I can redirect the user to either

link1.com

link2.com

link3.com

Does anyone have a quick modification for this?

Thank you in advance.

<?php

    require_once('geoplugin.class.php');
    $geoplugin = new geoPlugin();
    $geoplugin->locate();


    $geo_region = $geoplugin->region;  

    switch($geo_region) {
        case 'CA':
             header('Location: http://www.link1.com');
             exit; 



        default: // exceptions
               header('Location: http://www.everyoneelsegoeshere.com');
               exit;

         }

 ?>

1条回答
做个烂人
2楼-- · 2020-05-03 13:15

Try This one:

require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
$geo_region = $geoplugin->region;



switch($geo_region) {
    case 'CA':
    $links = array('link1.com','link2.com','link3.com');
    header('Location: http://'.$links[array_rand($links)]);
    exit; 
    default: // exceptions
    header('Location: http://www.everyoneelsegoeshere.com');
    exit;
}
查看更多
登录 后发表回答