Re: PHP Page Refresh on Redirection
| From: | Justin French | Date: | Tue, 28 Jan 2003 06:53:23 +0000 |
| Subject: | Re: PHP Page Refresh on Redirection | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-133348@lists.php.net to get a copy of this message | ||
on 28/01/03 4:42 PM, Phil (philcava@attbi.com) wrote:
> I have a PHP page with a form that submits to another PHP processing page.
> On completion of the PHP actions on the processing page, I have echoed into
> the page the javascript action of 'location.href=...' and the location is
> redirected to the PHP form page that starting the process. Both pages take
> data from an SQL server. The problem I'm having is that the the javascript
> always grabs the cached page. I need a newly refreshed page to return with
> updated data from the SQL server. Any suggestions?
In addition to sending the correct no-cache headers (which don't always work
with certain browsers and clients), you could also attach a random string to
the URL as a GET variable, so that the browser thinks it's a NEW, unread
URL.
include this function (straight from the manual) via a function library:
<?
function make_seed() {
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
?>
Then to get a random number,
<?
// seed the rand no generator and get a rand value
srand(make_seed());
$randval = rand();
?>
Then you can echo it as a get var or querystring on any URL:
location.href = page.php?r=<?=$randval?>
location.href = page.php?<?=$randval?>
Justin