Refresh only one time?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevin7
Forum Commoner
Posts: 96
Joined: Fri May 21, 2004 6:54 am

Refresh only one time?

Post by kevin7 »

hmm.. is that we can make a page refresh only one time?..

actually... what i hving is... after i upload a new image, the webpage still showing the old one... so, i've to refresh it for display the new...

anyway else besides of refresh can solve this problem?
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

put the upload code in another page, after uploading, redirect the user back?

or keep it in same page, after uploading, use [php_man]header[/php_man]() to redirect the user.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

Code: Select all

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
This will stop your page from being cache'd and therefore will only show the latest content.
choppsta
Forum Contributor
Posts: 114
Joined: Thu Jul 03, 2003 11:11 am

Post by choppsta »

The Pragma no cache may work...

What's happening is that the image is being cached by the browser, not the page it's displayed on. To stop this you could try adding a random querystring to the image path to trick the browser into thinking it's a different file..

E.g. <img src="myimage.gif?random=849372543">

The other solution is to write a small PHP script that get's the image and outputs it. Cos PHP pages don't tend to be cached and you can write out your own headers you can force it to refresh. So your image url would look something like..

E.g. <img src="getimage.php?image=imageid">
kevin7
Forum Commoner
Posts: 96
Joined: Fri May 21, 2004 6:54 am

Post by kevin7 »

hmm... i've one page for upload...
another page for information...
and another is to view...

so, which page should i put the code?

Code: Select all

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
anyway, i'm also curious to know if possible to refresh one time... :wink:
kevin7
Forum Commoner
Posts: 96
Joined: Fri May 21, 2004 6:54 am

Post by kevin7 »

anyone? can refresh one time?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

YOu can't stop a user from refreshing if thats what your trying to accomplish.
Also, when asking a question, try and use atleast better english than what you are using, so people can understadn what you're saying...
choppsta
Forum Contributor
Posts: 114
Joined: Thu Jul 03, 2003 11:11 am

Post by choppsta »

Ok, your original question was:

"anyway else besides of refresh can solve this problem?"

To which I have provided two possible solutions to try... Other people have also provided possible solutions..

Your question now appears to be:

"anyone? can refresh one time?"

My intepretation of this is that you want to know if there's a way to force a browser/client to refresh a page. By "one time" I presume you mean you want the client to refresh the page once and then cache the page on subsequent requests.

If the solutions given here are used conditionally after an upload this should do what you are asking.

If you need more help I'd suggest reading up on cache control and how web servers work in general. I think also having an understanding of WHY something is happening is much more important than just HOW to solve it.
kevin7
Forum Commoner
Posts: 96
Joined: Fri May 21, 2004 6:54 am

Post by kevin7 »

ooo... :oops: sorry dude, for my bad english and attitude...

hmm.. ok i ask my question again...

how can i made a page that able to refresh itself after the page is loaded...

i use onload=javascript:history.back(0) in body tag... the page keep refresh infinitely..

and after that, i use meta tag... it also keep refresh infinitely...

so, what i want is, refresh only 1 time after the page is loaded...

did i made myself clear? lol...
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

function build_qs($get) {
      $ret = '';
      foreach($get as $name => $value) {
          if(strlen($ret)) $ret .= '&';
          $ret .= urlencode($name) . '=' . urlencode($value);
      }
      return $ret;
  }

if( !empty($_GET['refresh_me']) ) {
  unset($_GET['refresh_me']);
  echo "<meta http-equiv='Refresh' content='3; " . $_SERVER['PHP_SELF'] . '?' . build_qs($_GET) ."' />";
}

echo "Link to refresh once after load: <a href='$_SERVER[PHP_SELF]?refresh_me=1'>Click here</a>";
Post Reply