Problem with refreshing

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
wizzard81
Forum Commoner
Posts: 66
Joined: Wed Jan 15, 2003 6:05 am
Location: Belgium
Contact:

Problem with refreshing

Post by wizzard81 »

Hello,

I made a upload script for images but i have a problem. After the picture is uploaded i bring the user back to the picture index page. But then i see the old picture and i have to refresh. Is this a fix for this because some of my users did not know they have to refresh?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

after you upload the image, before it is displayed to the page, call a new query to get the newest image or image name
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sounds like a caching problem.. maybe attach random garbage as a query string to the images?
wizzard81
Forum Commoner
Posts: 66
Joined: Wed Jan 15, 2003 6:05 am
Location: Belgium
Contact:

Post by wizzard81 »

? can you explain
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you use a script to return the images correct? add random data to the query string like so:

Code: Select all

<img src=&quote;my_image_script.php?id=123&amp;g=12341b43bzasdf87214&quote; />
User avatar
hyper_st8
Forum Newbie
Posts: 20
Joined: Mon Aug 18, 2003 5:27 am
Contact:

Post by hyper_st8 »

A good way of getting around the page caching is to use:

header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

At the top your page.

I found the information at http://uk2.php.net/manual/en/function.header.php
wizzard81
Forum Commoner
Posts: 66
Joined: Wed Jan 15, 2003 6:05 am
Location: Belgium
Contact:

Post by wizzard81 »

strange it still the same with the header at the top

i call my image like this=>

<img border=0 src=images/profiles/<? echo $row_picture["picture"]; ?>

after the picture is uploaded i work this way =>
header("Location: myprofile.php");

can this be the problem?
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

on the same link that hyper gave you, it stated that using the header wouldn't work on image files. Also, that same poster mentioned just exactly what feyd was suggesting :) try that.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

hongco wrote:on the same link that hyper gave you, it stated that using the header wouldn't work on image files.
Are you sure abt this ?
I assumed

Code: Select all

header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0');
will never get images from cache.
Im pretty sure abt this because I made a gallery script and it was far faster when I removed the header.
Last edited by anjanesh on Fri Mar 18, 2005 1:15 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

anjanesh wrote:

Code: Select all

header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0');
will never get images from cache.
Im pretty sure abt this because I made a gallery script and it was far faster then I removed the header.
correct
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

i had no problem with my gallery script either. it was wizard who had the problem, and the person who experienced the same thing suggested to use some random query. I have not tried that myself :)
Post Reply