2015-10-05 31 views
0

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

现在,代码只允许我将用户重定向到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; 

     } 

?> 

回答

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