如何在PHP中使这些链接旋转?

  • 本文关键字:链接 旋转 PHP php
  • 更新时间 :
  • 英文 :


下面是我使用的代码。

我希望能够旋转一个随机链接到用户。

不只是link1.com,我想让它在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;
         }
 ?>

试试这个:

require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
$geo_region = $geoplugin->region;
$links = array('link1.com','link2.com','link3.com');
switch($geo_region) {
    case 'CA':
         header('Location: http://'.$links[array_rand($links)]);
         exit; 
    default: // exceptions
        header('Location: http://www.everyoneelsegoeshere.com');
        exit;
    }

最新更新