p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Auto refreshing page


Message #1 by "Christopher Brown" <chris@k...> on Tue, 9 Apr 2002 23:43:00
How do I get a page to refresh at after a specified time.
here is my code so far
*************************88
<html>
<head>
<title>Browny's Webcam</title>
</head>
<body>
<?php
$refresh = (isset($refresh))? intval($refresh) : 5;
?>

<img src="http://browny.dyndns.org/webcam/pic/image.jpg">
<br>
<form method=post action webcam.php>
Select your desired refresh rate.
<select name="refresh">
<option value=1>1 second</option>
<option value=2>2 seconds</option>
<option value=3>3 seconds</option>
<option value=4>4 seconds</option>
<option value=5>5 seconds</option>
<option value=10>10 seconds</option>
<option value=20>20 seconds</option>
<option value=30>30 seconds</option>
<option value=60>1 minute</option>
</select>
<br>
<input type=submit value="click here to change refresh rate">
<br>
</form>
<br>
Default setting is 5 seconds
</body>
</html>
******************
At the moment all it does is to display a pictue and a drop down menu with 
time frames.  How do I get it to refresh the page after $refresh seconds.
Message #2 by "Nikolai Devereaux" <yomama@u...> on Tue, 9 Apr 2002 15:42:00 -0700
You can output a meta tag which does it.  I *think* this would do it:

echo "<META HTTP-EQUIV=Refresh CONTENT=\"$refresh; URL=$PHP_SELF\">\n";


nik
Message #3 by Jacob Cohen <cohen@r...> on Tue, 9 Apr 2002 15:41:37 -0700
On 4/9/2002,  <chris@k...> wrote:
> How do I get a page to refresh at after a specified time.
> here is my code so far

There are two ways to do this, both involve executing client-side code
in the browser.
You can either use a <meta http-equiv="refresh"> tag to have the
browser auto-refresh the page, or use javascript to set a timeout that
reloads the page in the browser.

Either way, you simply need to have your PHP script generate the HTML
or Javascript that does the refresh, then plug in your value for the
timeout value.

-- 
Regards,
Jake                            mailto:cohen@r...

Message #4 by "Nikolai Devereaux" <yomama@u...> on Tue, 9 Apr 2002 15:47:39 -0700
the javascript to do it:

http://grizzlyweb.com/webmaster/javascripts/refresh.asp

Message #5 by "Nikolai Devereaux" <yomama@u...> on Tue, 9 Apr 2002 15:49:03 -0700
Actually that javascript link is pretty informative.  I didn't realize that
the <META> tag tends to add pages to the history list of most browsers...

A fast and informative read.

Message #6 by "Luis Morales" <luismorales@j...> on Thu, 11 Apr 2002 00:59:48 -0400
Use this html tags and...

<?
if ( !(isset($refresh)){
   $refresh = 60;
}
?>
<head>
  <title>Chat Manageree</title>
  <META HTTP-EQUIV="refresh" CONTENT="<? echo $refresh?>">
  <META HTTP-EQUIV="Cache-Control: no-store, no-cache, must-revalidate">
</head>

Good Luck

LM

----- Original Message -----
From: "Christopher Brown" <chris@k...>
To: "beginning php" <beginning_php@p...>
Sent: Tuesday, April 09, 2002 11:43 PM
Subject: [beginning_php] Auto refreshing page


> How do I get a page to refresh at after a specified time.
> here is my code so far
> *************************88
> <html>
> <head>
> <title>Browny's Webcam</title>
> </head>
> <body>
> <?php
> $refresh = (isset($refresh))? intval($refresh) : 5;
> ?>
>
> <img src="http://browny.dyndns.org/webcam/pic/image.jpg">
> <br>
> <form method=post action webcam.php>
> Select your desired refresh rate.
> <select name="refresh">
> <option value=1>1 second</option>
> <option value=2>2 seconds</option>
> <option value=3>3 seconds</option>
> <option value=4>4 seconds</option>
> <option value=5>5 seconds</option>
> <option value=10>10 seconds</option>
> <option value=20>20 seconds</option>
> <option value=30>30 seconds</option>
> <option value=60>1 minute</option>
> </select>
> <br>
> <input type=submit value="click here to change refresh rate">
> <br>
> </form>
> <br>
> Default setting is 5 seconds
> </body>
> </html>
> ******************
> At the moment all it does is to display a pictue and a drop down menu with
> time frames.  How do I get it to refresh the page after $refresh seconds.
>
>

Message #7 by "Christopher Brown" <chris@k...> on Thu, 11 Apr 2002 20:16:49
I sorted most of it out using java script however, when I pick an option 
from the dropdown box it keeps popping up asking me to resend the info.
If I leave it on default then it works fine.

here is the code
*******************
<?php
$refresh = (isset($refresh))? intval($refresh) : 5;
?>
<html>
<head>
<script language="JavaScript">
<!--
var sURL = unescape(window.location.pathname);
function doLoad()
{
<?php
echo("setTimeout( \"refresh()\", $refresh*1000 ); ");
?>
}
function refresh()
{
    window.location.href = sURL;
}
//-->
</script>
<script language="JavaScript1.1">
<!--
function refresh()
{
   window.location.replace( sURL );
}
//-->
</script>
<script language="JavaScript1.2">
<!--
function refresh()
{
    window.location.reload( true );
}
//-->
</script>
<title>Browny's Webcam V1b</title>
</head>
<body>
<body onload="doLoad()">
<?php
echo ("<br>");
echo ("<img src=\"http://browny.dyndns.org/webcam/pic/image.jpg\">");
echo ("<br>");
echo ("This picture was updated at ") ;
$ht=gmDate("H") + 1;
echo gmDate("$ht i s");
?>
<br>
<form method=post action setwebcam.php>
Select your desired refresh rate.
<select name="refresh">
<option value=90>Please select a value</option>
<option value=1>1 second</option>
<option value=2>2 seconds</option>
<option value=3>3 seconds</option>
<option value=4>4 seconds</option>
<option value=5>5 seconds</option>
<option value=10>10 seconds</option>
<option value=20>20 seconds</option>
<option value=30>30 seconds</option>
<option value=60>1 minute</option>
</select>
<br>
<input type=submit value="click here to change refresh rate">
<br>
</form>
Default setting is 5 seconds.
<br>
<br>
<br>
Coming in v2.1 borders by request of Cpt_Fantastic
<br>
<br>
webcam.php V1b Dev Team
<BR>
Browny: Writer
<br>
Chaostime: Beta tester
<br>
Cpt_Fantastic: Beta tester
</body>
</html>
***********************
if you would like to see it in action then pop along to 
http://browny.dyndns.org/webcamv2b.php


  Return to Index