FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Can I refresh a page using php?





DoctorBeaver
I've got an annoying little problem.

I'm testing my php/mySQL application using JSAS with Opera browser. However, when I make an alteration to the code and try running it again, I get the old version. I assume this is a problem with Opera caching the pages. Although it's annoying, it's usable on pages that actually display something; I just hit the Opera "refresh" button.

However, I've got pages that DON'T display anything (most of the database access is on pages that don't display unless there's an error) so I can't use the Opera refresh. I have to quit Opera completely each time. That's particularly tiresome as I keep this forum, another forum, gmail,Yahoo mail and a couple of other sites loaded in Opera windows for convenience. I either have to re-open them every time Opera re-starts, or go without them being open,

Is there any way I can force the latest version of the program to be used?
AftershockVibe
You can use a HTML redirect to redirect to itself and cause a refresh. It depends on the browser whether it will just fetch from the cache though.

Try it and see;
Code:
<meta http-equiv="refresh" content="2; URL=whatever.php">


Obviously, you'll want to replace "whatever.php" with the page that is running the code (__FILE__ might be a good idea if you might rename it). Also, the number 2 is the time in seconds after the page loads before the redirect. You'll probably want to set that to zero.

EDIT: It needs to go in your <head> of the page

Also, when you actually do the redirect you will want to probably set a address line variable that tell the page not to refresh again otherwise it will refresh itself forever!

eg
Code:
<?php

echo '<head>';

IF($_GET['r'] != 'done')
{
echo '<meta http-equiv="refresh" content="2; URL=' . __FILE__  . '?r=done">';
\\ Prints redirect to [myself.php]?r=done
}

.. rest of page
DoctorBeaver
Thanks Aftershock, I'll give that a go.

However, I'm not sure I understand what you mean by this:-

Quote:
(__FILE__ might be a good idea if you might rename it)
cafefort
Hi Doc!

Well i think I understand your problem: you don't pages to be cached, isn't it?

You want the browser (here opera) to not keep a cached version of the page and ask the server to serve it again.

You can do that by adding this meta to your page:

Code:
<html>
<head>
...
<meta http-equiv="PRAGMA" content="NO-CACHE" />
..
</head>
<body>
...
</body>
</html>


Hope this helps Smile
DoctorBeaver
cafefort - thank you. That will be perfect for pages where I've got a Submit button Smile
AftershockVibe
DoctorBeaver wrote:
Thanks Aftershock, I'll give that a go.

However, I'm not sure I understand what you mean by this:-

Quote:
(__FILE__ might be a good idea if you might rename it)


__FILE__ is a PHP constant that contains the path and filename to the current document. Don't ask me why it doesn't have a $ in front of it.

So, if you rename the file, it will still redirect to itself and you don't have to manually adjust the filename inside the echo statement.

Cool
DoctorBeaver
Great... thanks Very Happy
Nyizsa
cafefort wrote:
Code:

<meta http-equiv="PRAGMA" content="NO-CACHE" />

Yes, this is the solution. However, the pragma tag is deprecated. HTML 1.1 uses
Code:
<meta http-equiv="cache-control" content="no-cache" />

I had the same problem with developing and checking web pages. I suggest including the above <meta> tag in every page under development.

AftershockVibe wrote:
__FILE__ is a PHP constant that contains the path and filename to the current document.

I think it is better to use $_SERVER['PHP_SELF'].
DoctorBeaver
Quote:

I had the same problem with developing and checking web pages. I suggest including the above <meta> tag in every page under development.


At least it's not just me being silly! Thanks
AftershockVibe
Nyizsa wrote:

I think it is better to use $_SERVER['PHP_SELF'].


They both do more or less the same thing. Note that PHP_SELF will only ever return the relative path of the document whereas __FILE__ returns the absolute address (http://www...... etc) in most PHP versions.
Related topics
[tutor] How to protect images without htaccess using PHP
Using PHP
Includ Images using PHP.
How to start using PHP? Help!
Website Designing using PHP
how can i setup a page break for printer on html using php ?
How do i password protect a web page using html
Reading word documents using PHP?
I am trying to build a contact form using php and flash
Communicating between web pages
Want to see a phpinfo page showing php settings?
Using php to change content of a .txt
Table data print feature using php or javascript?
Help displaying pdfs using PHP
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.