Take the 2-minute tour ×

I'm looking to make a webpage that will show a random web site (within the current web page) and only show it for 15 seconds then show another page, etc. I would like the web page to get the list of web sites to show from a MySQL database.

I'm not sure if this is possible to do in PHP because I know you can use iframes in Javascript, but if it's possible I'd like to do it in PHP. If anyone could point me in the right direction or write a little bit of code it would be greatly appreciated.

share|improve this question
iframe and ajax –  Dagon Jan 15 '12 at 4:06

4 Answers 4

up vote 1 down vote accepted

Add this to your HTML head:

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

Then, you can serve that page with a different iframe every time.

Here's an example:

<!DOCTYPE html>
        <title>Random website</title>
        <iframe src="<?php echo $website_pulled_from_database; ?>"></iframe>
share|improve this answer
how would I go about having a different iframe every time I'm slightly confused –  Twister Jan 15 '12 at 4:28
@Twister - I added some sample code for you. –  Joseph Silber Jan 15 '12 at 5:21
Thank you this looks great :) –  Twister Jan 15 '12 at 16:06

You can use header() in PHP


The code above will redirect the user to Google after 15 seconds

share|improve this answer
This would be good, except I would like the user to stay on my webpage, sort of like iframes. I'm just not sure how to do this in php –  Twister Jan 15 '12 at 4:51

You can use the sleep function in PHP instead of using jS if u are so adament on using pure PHP. But I see no point in doing that. http://php.net/manual/en/function.sleep.php You should also look into ajax in PHP.

share|improve this answer
the reason I'm using php purely is so users can't change what they view or for how long, the reason being that can easily be changed when coding in javascript by the user –  Twister Jan 15 '12 at 4:29
You should know that a user who is capable of editing a page's JS on the fly is likely to also be able to disable a meta refresh. –  njbair Jan 15 '12 at 5:30

Well, I dont think u need to do this in pure PHP. You can retrieve the contents from the DB and display them at whatever time you want using javascript. You can use the setInterval function for javascript(jQuery).

for. eg:

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

Hope this was of some help for you.

share|improve this answer
-1 The OP clearly said that he doesn't want to use Javascript. –  Joseph Silber Jan 15 '12 at 4:18
Well, I was just pointing him in the right direction. This doesnt have to be pure PHP. He said he doesnt want to do this using iframes n jS. –  Indy Jan 15 '12 at 4:24
I appreciate the effort, but yes I'm trying to stay away from javascript as it can be hacked very easily –  Twister Jan 15 '12 at 4:26
I dont see your point. We are retriving the data from the DB using PHP, we are using jS just to display it on screen and add some flair. I dont think there's any risk involved in doing this. Can u please explain how this is risky? Anyways, did u checkout the sleep function in PHP? –  Indy Jan 15 '12 at 4:35

Your Answer


