Jump to content
opus74

Refresh Page Once On Load

Recommended Posts

I read dallara's question in the forum, and I have a similar ??.

 

I acccess a radar image on my site, what I would like to do is:

 

1. user clicks on "view radar"

 

2. radar page & image loads

 

3. page immediately reloads

 

4. page displays & just sits there.

 

5. There is a <meta http-equiv="refresh" content="420"> in the radar page code

to refresh the image after 7 minutes when the radar updates.

 

The problem is, currently, a visitor gets an old image and then has to wait 7 minutes for current.

 

I really don't want to deal with a whole lot of caching/non-caching if I can avoid it. Just a "simple" reload??

 

Your thoughts & suggestions are appreciated.

Share this post


Link to post
Share on other sites

I would say either the meta refresh and PHP or Javascript.

 

At the VERY start of the page you'd put

 

><?php
$metaTag = '';
if (empty($_COOKIE['refreshed']))
{
  $metaTag = '<meta http-equiv="refresh" content="0">';
  setcookie('refreshed', 1);
}
?>

 

Then where the meta refresh tag goes put

 

><?php
echo $metaTag;
?>

 

This way the meta refresh tag should only appear the first time the page is loaded. I'd recommend this method over the javascript as a few may have javascript turned off.

Edited by carbonize

Share this post


Link to post
Share on other sites

Hmm, I must be doing this wrong, it is displaying :

 

'setcookie('refreshed', 1);

 

at the top of the page ......

Edited by opus74

Share this post


Link to post
Share on other sites
Did you copy my code exactly ?

 

Yes, just after <head>.

 

Here's a shot....GIF killed the graphics ......

 

sorry, I don't have upload permission here ... but it puts the 'setcookie('refreshed', 1); at the top of the page.

Share this post


Link to post
Share on other sites

No

 

><?php
$metaTag = '';
if (empty($_COOKIE['refreshed']))
{
  $metaTag = '<meta http-equiv="refresh" content="0">';
  setcookie('refreshed', 1);
}
?>

 

That needs to be the very first thing on the page. Nothing before it. No white space, no HTML, nothing.

Share this post


Link to post
Share on other sites

Opus -- I think that the problem might be that you put php code in a page that has an .html or .htm extension. If you rename the page to a .php extension then the code that Carbonize gave you will work fine.

 

Please note: If the page has been indexed by the search engines, or saved by users, then you will also want to put in a redirect for the "whatever_the_name_is.html" to "whatever_the_name_is.php".

Share this post


Link to post
Share on other sites

Sidenote...

 

Images can not be uploaded into the posts (as attachments). They must be linked/inserted into the posts from your own server space etc.

Share this post


Link to post
Share on other sites

Personally I'd recommend something like imageshack.us for times like this where you want to post a picture on a forum that has attachments disabled.

Share this post


Link to post
Share on other sites
Opus -- I think that the problem might be that you put php code in a page that has an .html or .htm extension. If you rename the page to a .php extension then the code that Carbonize gave you will work fine.

 

Please note: If the page has been indexed by the search engines, or saved by users, then you will also want to put in a redirect for the "whatever_the_name_is.html" to "whatever_the_name_is.php".

If the page does have an .html extension

put this in your .htaccess flie to make it work without changing the extension.

>AddHandler application/x-httpd-php .htm .html

 

And search engines indexing won't matter.

Share this post


Link to post
Share on other sites
If the page does have an .html extension

put this in your .htaccess flie to make it work without changing the extension.

>AddHandler application/x-httpd-php .htm .html

 

And search engines indexing won't matter.

 

 

Don, I learn something new every time I read this forum. :)

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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...