使用 Geoplugin 旋转链接

2022-01-14 00:00:00 geolocation php

我是 geoplugin.class,用于将 CA 用户重定向到特定链接.

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

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

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?

提前谢谢你.

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

         }

 ?>

推荐答案

试试这个:

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

相关文章