使用Geoplugin旋转链接

时间:2015-10-05 18:04:00

标签: php geolocation

我使用geoplugin.class将CA用户重定向到特定链接。

现在代码只允许我将用户重定向到1个网站。我想修改此代码,以便将用户重定向到

link1.com

link2.com

link3.com

有人对此进行了快速修改吗?

提前谢谢。

<?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 个答案:

答案 0 :(得分:0)

试试这个:

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;
}