如何在php中显示不同的网站一段时间?

时间:2012-01-15 04:03:05

标签: php mysql

我正在制作一个网页,显示一个随机的网站(在当前网页内),只显示15秒,然后显示另一个页面等。我希望网页获取列表从MySQL数据库显示的网站。

我不确定这是否可以用PHP做,因为我知道你可以在Javascript中使用iframe,但如果有可能我想用PHP做。如果有人能指出我正确的方向或写一点代码,我们将不胜感激。

4 个答案:

答案 0 :(得分:1)

将此添加到您的HTML head

<meta http-equiv="refresh" content="15;url=http://www.yourdomain.com">

然后,您每次都可以使用不同的iframe投放该页面。


以下是一个例子:

<!DOCTYPE html>
<html>
    <head>
        <title>Random website</title>
        <meta http-equiv="refresh" content="15;url=http://www.yourdomain.com">
    </head>
    <body>
        <iframe src="<?php echo $website_pulled_from_database; ?>"></iframe>
    </body>
</html>

答案 1 :(得分:0)

如果你非常喜欢使用纯PHP,你可以在PHP中使用sleep函数而不是使用jS。但我认为没有必要这样做。 http://php.net/manual/en/function.sleep.php 您还应该在PHP中查看ajax。

答案 2 :(得分:0)

您可以在PHP中使用header()

header('refresh:15;url=http://www.google.com/');

上述代码会在15秒后将用户重定向到Google

答案 3 :(得分:-1)

好吧,我不认为你需要在纯PHP中这样做。您可以从数据库中检索内容,并在任何时候使用javascript显示它们。您可以将setInterval函数用于javascript(jQuery)。

有关。例如:

<script type="text/javascript">  
  $(function(){  
        var i=0;  
         $('li').not(':first').hide();//Hide everything other than the first li item  
          setInterval(function(){  
              $('li').eq(i).hide();//Hide the current li item  
              i++;    
              if($('li').eq(i).text().length==0) //check if it is the last li item  
                {  
                 i=0;  
                }  
              $('li').eq(i).fadeIn(1000); //FadeIn the next li item              
             },3000);                  
       });        
</script> 

希望这对你有所帮助。

相关问题