Force refresh ( Ctrl-F5 )

Hi there

I’m generasting some images using jpgraph library. Those images are generated dinamically based user inputs.
Sometimes the user has to press ctrl-F5 in order to see the new graphic.

How to solve this problem?

you can auto-refresh the page by <meta >tag

secondly you can give a button and add a click event with function to refresh the page.

Thanks,

use header() to send headers which tell the browser not to cache the image, in the script where the binary image data is output(the jpgraph code).

But…often you would be supplying the dynamic data to the script with a query string of arguments. like image.php?width=50&height=50&color=red. If the url changes, then the browser will see this and automatically know it needs to download the new version. If the url doesn’t change, you want the browser to cache the image.

How does your script get the data it needs to generate the image, if its not the url?

I’m assuming that it’s a specific graph that is regenerated occasionally. The URL wouldn’t change then. In that case, use the right headers as crmalibu suggested.

Something like on here:
http://digitalpaint.therisenrealm.com/tools/pubstats

I generate the image from a mysql db

how can i do that? can you give me a link or a sample? can I use this for some images only(some types, or some rules)?

Here you go, direct from the manual. :slight_smile:

Make sure you only change the header when you changed your image, so you still cache them a bit.

Another way would be to store and “update time” next to each image, and to use mod rewrite to put that id in the URL next to the image ID you want.
Like: /images/users/1234/23423.jpg
1234 = image ID to load
23423 = last update time or revision #, witch changes every time you alter the image with the ID 1234.

That way, if you change your image, your users will always get the new image.
If you don’t change the image, users will use the cached image instead.

Problem is, when you type in your image URL in your script, you also need that revision/last update time # (but you can call a function to do it automatically).

You can also do image.jpg?322425

That way, if you’re not able to get the current revision number, you can still show the image in the worst case.

Are you storing the image on the filesystem? Or are you linking directly to a php script, like <img href=“image.php”

If you want a good answer thats optimal for your situation, you need to provide more info.

Anyway, usually the best approach for images and other external resources is to let the resource be cached(and actually suggest to the browser that it should cache it for a pretty decent amount of time). When you want it to change, you change the url in your html(changing the query string works).

the lib I’m using jpGraph is writing the file bassed on mysql data’s on the disk and I display it as <img src=“img1.png” >

You can store them in the database, set the links to:
<img src=“/images/user_image_12345.jpg” …

And then using mod rewrite, turn that to:
view_user_image.php?user_id=12345

So the end user will have no idea if your images are on the file system or database.

So you can store them wherever you want.
Just remember that there is a limit of files you can have on the file system… and backups are easier to do to a database than a hard drive.

There’s a limit to what you can have in a database too.
Good luck reaching those limits with actual data. :wink:

It’s not so hard to backup the files on your site. Manually download them to your hard drive and store in a date-code folder, or write a simple PHP script to archive it all for you and let you download a zip.

To the OP: If your users are constantly changing the images around, it might be a better idea to let the PHP serve the image directly instead of storing on disk.