tags:

views:

1508

answers:

11

Here's a challenge that I was tasked with recently. I still haven't figured out the best way to do it, maybe someone else has an idea.

Using PHP and/or HTML, create a page that cycles through any number of other pages at a given interval.

For instance, we would load this page and it would take us to google for 20 seconds, then on to yahoo for 10 seconds, then on to stackoverflow for 180 seconds and so on an so forth.

+1  A: 

Use a separate iframe for the content, then use Javascript to delay() a period of time and set the iframe's location property.

Jason Cohen
+1  A: 

When you are taken to another site (e.g. Google) control passes to that site, so in order for your script to keep running, you'd need to load the new site in a frame, and keep your script (which I'd imagine could most readily be implemented using Javascript) in another frame (which could be made very small so you can't see it).

Ben
A: 

You could do this with JavaScript quite easily. It would help to know the deployment environment. Is it a kiosk or something?

For the JavaScript solution, serve up a page that contains a JavaScript that will pop open a new browser window. The controller page will then cause the new browser window to cycle through a series of pages. That's about the simplest way to do this that I can think of.

Edit: Agree with Simon's comment. This solution would work best in a kiosk or large, public display environment where the pages are just being shown without any user interaction.

shadit
A: 

Depends on your exact requirements. If you allow JavaScript and allow frames then you can stick a hidden frame within a frameset on your page into which you load some JavaScript. This JavaScript will then control the content of the main frame using the window.location object and setTimeout function.

The downside would be that the user's address bar would not update with the new URL. I'm not sure how this would achievable otherwise. If you can clarify the constraints I can provide more help.

Edit - Shad's suggestion is a possibility although unless the user triggers the action the browser may block the popup. Again you'd have to clarify whether a popup is allowable.

Simon Collins
A: 

Create a wrapper HTML page with an IFrame in it, sized at 100% x 100%. Then add in some javascript that changes the src of the IFrame between set intervals.

hasseg
A: 

I think it would have to work like gabbly.com, which sucks in other websites and displays them with its own content over it.

Once you read the other site in and were ready to display it, you couldn't really do it "in PHP"; you would have to send an HTML redirect meta-tag:

<meta HTTP-EQUIV="REFRESH" content="15; url=http://www.thepagecycler.com/nextpage.html"&gt;

Or you could use Javascript instead of the meta-tag.

Max
A: 

This is not doable in a PHP script, unless you want to edit the redirect.... PHP is a back end technology; you're going to need to do this in Javascript or the like.

The best you're going to do, as far as I know, is to create a text file on your web server and load a different HTTP address based on time out of that text file, then redirect the browser to the site found in that text file.

A: 

The first solution that jumps to mind is to do this in a frameset. Hide one of the frames, and the other display the pages in question. Drive the page transitions with Javascript from the hidden frame.

function RefreshFrame()
{
    parent.VisibleFrame.location.href = urlArray[i];
    i++;

    if(i < urlArray.length) SetTimeout("RefreshFrame()", 20000);
}

var i = 0;
var urlArray = ['http://google.com','http://yahoo.com', 'http://www.search.com'];
RefreshFrame();

In this example the Javascript would be in the hiddend frame, and you would name your visible frame "VisibleFrame".

Disclaimer: I just wrote this code in the comment window and have not tested it

Jason Jackson
A: 

The theory behind the request is basically the ability to cycle through web page dashboards for various systems from a "kiosk" PC. I oversee a data center and we have several monitor systems that allow me view dashboards for temps, system up time, etc etc. The idea is load a page that would cycle from dashboard to dashboard remaining on each for an amount of time specified by me, 1 minute on this board, 30 seconds on the next board, 2 minutes on the next and so on.. Javascript is absolutely allowable (though I have little experience with it). My mediums of choice are PHP/HTML and I'm not seeing a way to make this happen cleanly with just them..

GreenO
+5  A: 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html lang="en">
<head>
<title>Dashboard Example</title>
<style type="text/css">
body, html { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
iframe { border: none; }
</style>
<script type="text/javascript">
var Dash = {
    nextIndex: 0,

    dashboards: [
        {url: "http://www.google.com", time: 5},
        {url: "http://www.yahoo.com", time: 10},
        {url: "http://www.stackoverflow.com", time: 15}
    ],

    display: function()
    {
        var dashboard = Dash.dashboards[Dash.nextIndex];
        frames["displayArea"].location.href = dashboard.url;
        Dash.nextIndex = (Dash.nextIndex + 1) % Dash.dashboards.length;
        setTimeout(Dash.display, dashboard.time * 1000);
    }
};

window.onload = Dash.display;
</script>
</head>
<body>
<iframe name="displayArea" width="100%" height="100%"></iframe>
</body>
</html>
insin
there's a small error -- frames["displayArea"].location.href = dashboard.url;should readframes["displayArea"].location.href = dashboards.url;
Pete Michaud
A: 

I managed to create this thing. It's not pretty but it does work.

<?php
# Path the config file, full or relative.
$configfile="config.conf"; 
$tempfile="tmp.html";
# Read the file into an array
$farray=file($configfile);  
# Count array elements
$count=count($farray);  
if(!isset($_GET['s'])){
    $s=0;
}else{  
    $s=$_GET['s'];
if($s==($count-1)){ # -1 because of the offset in starting our loop at 0 instead of 1
 $s=0;
}else{
 $s=$_GET['s']+1; # Increment the counter
}
}
# Get the line from the array
$entry=$farray[$s];
# Break the line on the comma into 2 entries
$arr=explode(",",$entry);       
# Now each line is in 2 pieces - URL and TimeDelay
$url=strtolower($arr[0]);
# Check our url to see if it has an HTTP prepended, if it doesn't, give it one.
$check=strstr($url,"http://"); 
if($check==FALSE){
    $url="http://".$url;
    }           
# Trim unwanted crap from the time
$time=rtrim($arr[1]);      
# Get a handle to the temp file
$tmphandle=fopen($tempfile,"w");
# What does our meta refresh look like?
$meta="<meta http-equiv=\"refresh\" content=\"".$time.";url=index.php?s=".$s."\">\n";
# The iframe to display
$content="<iframe src =\"".$url."\" height=\"100%\" width=\"100%\"></iframe>";
# roll up the meta and content to be written
$str=$meta.$content;
# Write it
fwrite($tmphandle,$str);
# Close the handle
fclose($tmphandle);
# Load the page
die(header("Location:tmp.html"));            
?>

Config files looks like (URL, Time to stay on that page): google.com,5 http://yahoo.com,10

GreenO