Jump to content

Is there a PHP function to force a browser refresh


eatc7402

Recommended Posts

I have an html page that gets updated about once a week. I would like

to FORCE the browser (IE, Firefox, Netscape, or Opera) to REFRESH

when the user opens the page to ensure they receive the latest

update. Been searching around for some php

code to add to the page to accomplish this

without success. Can anyone give me

a steer to how to accomplish this. Thanks.

 

Dave, eatc7402

 

Link to comment
Share on other sites

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?> 

 

Is what he was referring to. As to making the browser refresh, without javascript or some type of a time function it is really not possible. If you want a refresh after a certain amount of time Javascript is what you want.

Link to comment
Share on other sites

PHP could refresh with a header request to the same page, but that would be pointless since it would be processed before the script, thus sending you into an infinite loop (unless you flagged some variable, but I don't see a use behind that).

Link to comment
Share on other sites

Well this ALMOST seems to work. If I force the page to go to a

DIFFERENT url than the one I'm already on, it works.

 

But, I don't want to go to another page, I simply want to force

a REFRESH of the one I'm already on.

 

So, turning the new url into the page I'm already on

causes a LOOP of refreshes that continues forever. I tried to add

an exit statement but that did not seem to fix it.

 

Also somethings wrong with the syntax, as I see a

"; ?>

 

on the screen which are the last 5 characters of the echo command

not being properly recognized. Hummm.

 

eatc7402

Link to comment
Share on other sites

this works fine

 

simple HTML

<?php
echo "<meta http-equiv='refresh' content='5;http://mydomain.com/page1.php'>";
?>

 

change 5 to the number of seconds

 

 

what exactly are you trying to do ?

 

heres how i used it (as part of a download script)

<?php
if( isset($_GET['DL']) )
{
//download
}else{
echo "please wait...";
echo "<meta http-equiv='refresh' content='5;{$_SERVER['REQUEST_URI']}?DL=1'>";
}
?>

 

Link to comment
Share on other sites

What exactly am I trying to do??

 

I want to find a way to ensure that even if the user has the html page chache

turned ON, that they will get a REFRESHED copy of a particular html page

EACH time they view it, so they do not MISS updates.

 

eatc7402

 

Link to comment
Share on other sites

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?> 

 

Is what he was referring to. As to making the browser refresh, without javascript or some type of a time function it is really not possible. If you want a refresh after a certain amount of time Javascript is what you want.

 

What is wrong with this code? If that is set on the page anytime a user refreshes the page it revalidates it.

 

Now if you want to send a signal when you do an update to every page a user is on to refresh, that would require AJAX. I would suggest googling AJAX for how to do that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.