테스트 사이트 - 개발 중인 베타 버전입니다

sub 페이지가 열릴 때 마다 mt_rand()를 이용하여 나오게 할 수 있을까요? 채택완료

더블피디 8년 전 조회 2,680

아래 그림처럼 Main Page(index)일 때는 좌우측배너가 side1, side2가 나오도록 하고

나머지는 모두 side3, side4 페이지가 나오도록 하였습니다. 

 

 

 

아래 코드로 출력을 하면 페이지 오픈 때마다 랜덤값이 출력되는데요

<?php  echo  'mt_rand(1, 4) : '.mt_rand(1, 4).'<br>'; ?>

 

mt_rand(1,4) 이 함수를 이용하면 될듯한데 어떻게 적용을 하면 될까요?

 


 

 

 

</p><p><?php if(defined('_INDEX_')) { // index에서만 실행 ?></p><p><div style="position:absolute; width:160px; left:50%; margin-left:-710px; margin-top:55px; z-index:999;"></p><p>   <iframe src="/banner/side2.html" width="160" height="600" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe></p><p></div></p><p><div style="position:absolute; width:160px; left:50%; margin-left:580px; margin-top:55px; z-index:999;"></p><p>   <iframe src="/banner/side1.html" width="160" height="600" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe></p><p></div></p><p><?php } else { ?></p><p><div style="position:absolute; width:160px; left:50%; margin-left:-710px; margin-top:55px; z-index:999;"></p><p>   <iframe src="/banner/side3.html" width="160" height="600" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe></p><p></div></p><p><div style="position:absolute; width:160px; left:50%; margin-left:580px; margin-top:55px; z-index:999;"></p><p>   <iframe src="/banner/side4.html" width="160" height="600" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe></p><p></div></p><p><?php } ?></p><p>

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
a
8년 전

혹시 서브 페이지에서는 side1 ~ side4까지 랜덤하게 나오게 하신다는 건가요?

이렇게 하면 어떨까요~

 

</p><p><?php
$banner = array(2, 1);
if (!defined('_INDEX_')) {
 $banner = array();
 while (count($banner) < 2) {
  $index = mt_rand(1, 4);
  if (!in_array($index, $banner)) {
   $banner[] = $index;
  }
 }
}
?></p><p><div style="position:absolute; width:160px; left:50%; margin-left:-710px; margin-top:55px; z-index:999;">
   <iframe src="/banner/side<?=$banner[0]?>.html" width="160" height="600" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</div>
<div style="position:absolute; width:160px; left:50%; margin-left:580px; margin-top:55px; z-index:999;">
   <iframe src="/banner/side<?=$banner[1]?>.html" width="160" height="600" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe> </p><p>
 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인