开发者

If is domain, display this array

Have two arrays. One shuffles images, other one has no shuffle. When you go to the website, it's supposed to display images in a random order. That works. Now, I'd like it if you're being forwarded from this other domain that it displays the other array with no shuffle.

Here's my array with no shuffle:

<?

$items1 = array(

    array('image'=>'/images/logos/1.png', 'link' => 'http://www.blah.com', 'text' => 'blah'),
    array('image'=>'/images/logos/2.png', 'link' => 'http://w开发者_如何学Cww.blah.com', 'text' => 'blah'),
    array('image'=>'/images/logos/3.png', 'link' => 'http://www.blah.com', 'text' => 'blah'),
    array('image'=>'/images/logos/4.png', 'link' =>     

    );

?>

Here's me trying an if else statement to display correct array:

<?php $domain = "http://www.blahblah.com";
        if ($domain == blahblah.com)
        { echo '<?foreach($items1 as $i1){?>
          <div>
              <a href="<?=$i1['link'];?>"><img width="400" height="200" src="<?=$i1['image'];?>"></a>
          </div>
       <? } ?>'; }
        else
        { echo '<?foreach($items as $i){?>
          <div>
              <a href="<?=$i['link'];?>"><img width="400" height="200" src="<?=$i['image'];?>"></a>
          </div>
       <? } ?>'; }
       ?>

Guide me to the light people! Thanks

greg0ire> code suggestion:

<?php $domain = "http://www.blahblah.com";
    if ($domain == "http://www.blahblah.com"):// use alternative syntax in templates
      foreach($items1 as $i1): // do not try to "echo 'foreach'" ?>
      <div>
          <a href="<?=$i1['link'];?>"><img width="400" height="200" src="<?=$i1['image'];?>"></a>
      </div>
   <?php 
      endforeach;
    else:
      foreach($items as $i):?>
      <div>
          <a href="<?=$i['link'];?>"><img width="400" height="200" src="<?=$i['image'];?>"></a>
      </div>
   <?php 
       endforeach;
     endif;?>


I believe $_SERVER['HTTP_REFERER'] is what you're looking for... ?

PHP: $_SERVER - Manual


Actually, I think $_SERVER['SERVER_NAME'] is more what you're looking for.

HTTP_REFERER is where the user came from (as set by the useragent)

See: PHP:$_SERVER - Manual

You'll also need to check for both www.domain.com and domain.com (Unless you're set up to use either one or the other)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜