Rotate Links Using Geoplugin

白昼怎懂夜的黑 提交于 2019-12-02 17:30:35

问题


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:


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


来源:https://stackoverflow.com/questions/32954994/rotate-links-using-geoplugin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!