pavlenko
pavlenko

Reputation: 665

Php redirect and refresh redirected

I have page1.php from witch I update picture.

Updating is fine and after update, I redirect this page to picture.php:

header('Location: picture.php');

Redirect working fine,but problem is,there is no picture. If I refresh page,manualy, picture show on page.

I also try this:

header("Refresh:0; url=page2.php");

So, is there posibility to redirect from page1.php to picture.php,and after that,redirect picture.php, so user can se image withouth refres page?

Tnx

Upvotes: 0

Views: 1531

Answers (2)

Martin
Martin

Reputation: 22760

There are two parts to this: Refreshing PHP file structure memory, and refreshing the browsers cache.

1) You need to use clearstatcache(); ( http://php.net/manual/en/function.clearstatcache.php ) in order to tell PHP to refresh the file listing it keeps in its memory.

This should be done at the very top of the picture display page.
Try this if method 2 - below - does not work.

2) You can also force the browser to refresh the image URL by appending the URL with a random number so you force the page to refresh its search for the image, because

file.jpg?457458458754 is not the same as file.jpg?97767536436 in the <img> tag.

example: <img src="<?php print $imageFilename.mt_rand(1111111,99999999); ?>">

Upvotes: 1

Simone Nigro
Simone Nigro

Reputation: 4887

I think the browser retrieving the page from the local chache, to avoid try this:

header('Location: picture.php?nocache='.time());

In the 99.99999% of case browser use the entire url for cache resources. But some browsers apply a different cache strategy.

Upvotes: 0

Related Questions