Re: [PHP] Is it possible to stop an image from being cached?

2007-07-27 Thread Richard Heyes

Dan wrote:

...

You should also look at this:

http://www.mnot.net/cache_docs/

Very informative.

--
Richard Heyes
+44 (0)844 801 1072
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Is it possible to stop an image from being cached?

2007-07-26 Thread Chris Aitken
 Solution 1:
 Send a header() that avoids caching (can't remember it exactly)
 Solution 2:
 Call the image like this:
 img src=image.jpg?arandomstringhereeachtime
 Or if you were creating it with a php script:
 img src=image.php?img=image.jpgarandomstringhereeachtime

My preferred way of doing it, and making sure its reloaded each time is to
do it this way... the U variable pretty much guarantees a random string each
time its loaded.

image.jpg?.date(U).




Regards
 

Chris Aitken
The Web Hub Designer and Programmer
Phone : 02 4648 0808
Mobile : 0411 132 075
 
-
 
Making The Web Work The Web Hub
http://www.thewebhub.com.au/
[EMAIL PROTECTED]
 
-
 
Confidentiality Statement:  
This message is intended only for the use of the Addressee and may contain 
information that is PRIVILEDGED and CONFIDENTIAL.  If you are not the 
intended recipient, dissemination of this communication is prohibited.  
If you have received this communication in error, please erase all 
copies of the message and its attachments and notify us immediately.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is it possible to stop an image from being cached?

2007-07-26 Thread brian

Tijnema wrote:

On 7/26/07, Dan [EMAIL PROTECTED] wrote:

I have a situation where there is a single image let's call it 
somebody.jpg.
I want to be able to dynamicly create this image using php, basicilly 
I have
PHP set to handle .jpg files also, so I then go through and create an 
image

based upon some info I get from a database call and then use
header('Content-Type: image/jpeg');
passthru($file);
to send the image to the user.

My problem is once they view the image their browser helpfully 
caches it

so they don't have to download it again.

Is there any tactic short of changing the name constantly of the image to
avoid browser caching of an image?

- Dan



Solution 1:
Send a header() that avoids caching (can't remember it exactly)


You can try:

header('Cache-Control: no-store, no-cache, must-revalidate, 
Post-Check=0, Pre-Check=0');


brian

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is it possible to stop an image from being cached?

2007-07-26 Thread Dan
Well, this is only one specific image that constantly changes, the rest of 
the page is handled regularly.

From what you've said if I go with this

header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past

That will effect only the one specific image I use this on when generating 
it right?


- Dan

Tijnema [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

On 7/27/07, Dan [EMAIL PROTECTED] wrote:
Is this header you're refering to the header of the page which contains 
the

image, or the image itself?

- Dan


The image itself.

Also note, that if you use my solution 2, you still might get
problems, as the page that is calling might be cached, and in the
cached page, it refers to the image with the same unique code, and it
will use the cached image again.

Also, if you use solution 2, the image will still stay forever in the
temp folder of the browser(unless the user is cleaning it). If you use
solution 1, the browser will keep it only for this page, and will
remove it afterwards.

Tijnema


Tijnema [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On 7/27/07, brian [EMAIL PROTECTED] wrote:
 Tijnema wrote:
  On 7/26/07, Dan [EMAIL PROTECTED] wrote:
 
  I have a situation where there is a single image let's call it
  somebody.jpg.
  I want to be able to dynamicly create this image using php, 
  basicilly

  I have
  PHP set to handle .jpg files also, so I then go through and create 
  an

  image
  based upon some info I get from a database call and then use
  header('Content-Type: image/jpeg');
  passthru($file);
  to send the image to the user.
 
  My problem is once they view the image their browser helpfully
  caches it
  so they don't have to download it again.
 
  Is there any tactic short of changing the name constantly of the 
  image

  to
  avoid browser caching of an image?
 
  - Dan
 
 
  Solution 1:
  Send a header() that avoids caching (can't remember it exactly)

 You can try:

 header('Cache-Control: no-store, no-cache, must-revalidate,
 Post-Check=0, Pre-Check=0');

 brian

 That's HTTP/1.1 only, but this is what I got from PHP site:
 ?php
 header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1
 header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past
 ?

 Tijnema

 --
 Vote for PHP Color Coding in Gmail! - http://gpcc.tijnema.info

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
Vote for PHP Color Coding in Gmail! - http://gpcc.tijnema.info 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is it possible to stop an image from being cached?

2007-07-26 Thread Dan
Is this header you're refering to the header of the page which contains the 
image, or the image itself?


- Dan

Tijnema [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

On 7/27/07, brian [EMAIL PROTECTED] wrote:

Tijnema wrote:
 On 7/26/07, Dan [EMAIL PROTECTED] wrote:

 I have a situation where there is a single image let's call it
 somebody.jpg.
 I want to be able to dynamicly create this image using php, basicilly
 I have
 PHP set to handle .jpg files also, so I then go through and create an
 image
 based upon some info I get from a database call and then use
 header('Content-Type: image/jpeg');
 passthru($file);
 to send the image to the user.

 My problem is once they view the image their browser helpfully
 caches it
 so they don't have to download it again.

 Is there any tactic short of changing the name constantly of the image 
 to

 avoid browser caching of an image?

 - Dan


 Solution 1:
 Send a header() that avoids caching (can't remember it exactly)

You can try:

header('Cache-Control: no-store, no-cache, must-revalidate,
Post-Check=0, Pre-Check=0');

brian


That's HTTP/1.1 only, but this is what I got from PHP site:
?php
header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past
?

Tijnema

--
Vote for PHP Color Coding in Gmail! - http://gpcc.tijnema.info 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is it possible to stop an image from being cached?

2007-07-26 Thread Tijnema

On 7/27/07, Chris Aitken [EMAIL PROTECTED] wrote:

 header('Cache-Control: no-store, no-cache, must-revalidate,
 Post-Check=0, Pre-Check=0');

 brian

That's HTTP/1.1 only, but this is what I got from PHP site:
?php
header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past
?


But wouldn't that make every image on the page be uncached and reloaded each
time? Not very efficient if the shell of the site keeps getting loaded if
only 1 or 2 images need to be forced.




Regards


Chris Aitken
The Web Hub Designer and Programmer
Phone : 02 4648 0808
Mobile : 0411 132 075



Yes, that depends on which way it is used, I wouldn't recommend
loading images from the database that don't get changed...
And you can of course also use an
if-statement/switch-statement/in_array function in your image.php
script, like this:

$img = $_GET['img'];
if($img == test_a.jpg || $img == test_b.jpg) {
header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past
}

OR:

$img = $_GET['img'];
switch($img) {
case test_a.jpg:
case test_b.jpg:
header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past
}

OR:

$img = $_GET['img'];
$noncached_images = array(test_a.jpg,test_b.jpg);
if(in_array($img,$noncached_images)) {
header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past
}



Tijnema

--
Vote for PHP Color Coding in Gmail! - http://gpcc.tijnema.info

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is it possible to stop an image from being cached?

2007-07-26 Thread Tijnema

On 7/26/07, Dan [EMAIL PROTECTED] wrote:

I have a situation where there is a single image let's call it somebody.jpg.
I want to be able to dynamicly create this image using php, basicilly I have
PHP set to handle .jpg files also, so I then go through and create an image
based upon some info I get from a database call and then use
header('Content-Type: image/jpeg');
passthru($file);
to send the image to the user.

My problem is once they view the image their browser helpfully caches it
so they don't have to download it again.

Is there any tactic short of changing the name constantly of the image to
avoid browser caching of an image?

- Dan


Solution 1:
Send a header() that avoids caching (can't remember it exactly)
Solution 2:
Call the image like this:
img src=image.jpg?arandomstringhereeachtime
Or if you were creating it with a php script:
img src=image.php?img=image.jpgarandomstringhereeachtime

Tijnema

--
Vote for PHP Color Coding in Gmail! - http://gpcc.tijnema.info

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is it possible to stop an image from being cached?

2007-07-26 Thread Dan

Awesome, seems to work.  Thanks Tijnema!

- Dan

Dan [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
Well, this is only one specific image that constantly changes, the rest of 
the page is handled regularly.

From what you've said if I go with this
header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past

That will effect only the one specific image I use this on when generating 
it right?


- Dan

Tijnema [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

On 7/27/07, Dan [EMAIL PROTECTED] wrote:
Is this header you're refering to the header of the page which contains 
the

image, or the image itself?

- Dan


The image itself.

Also note, that if you use my solution 2, you still might get
problems, as the page that is calling might be cached, and in the
cached page, it refers to the image with the same unique code, and it
will use the cached image again.

Also, if you use solution 2, the image will still stay forever in the
temp folder of the browser(unless the user is cleaning it). If you use
solution 1, the browser will keep it only for this page, and will
remove it afterwards.

Tijnema


Tijnema [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On 7/27/07, brian [EMAIL PROTECTED] wrote:
 Tijnema wrote:
  On 7/26/07, Dan [EMAIL PROTECTED] wrote:
 
  I have a situation where there is a single image let's call it
  somebody.jpg.
  I want to be able to dynamicly create this image using php, 
  basicilly

  I have
  PHP set to handle .jpg files also, so I then go through and create 
  an

  image
  based upon some info I get from a database call and then use
  header('Content-Type: image/jpeg');
  passthru($file);
  to send the image to the user.
 
  My problem is once they view the image their browser helpfully
  caches it
  so they don't have to download it again.
 
  Is there any tactic short of changing the name constantly of the 
  image

  to
  avoid browser caching of an image?
 
  - Dan
 
 
  Solution 1:
  Send a header() that avoids caching (can't remember it exactly)

 You can try:

 header('Cache-Control: no-store, no-cache, must-revalidate,
 Post-Check=0, Pre-Check=0');

 brian

 That's HTTP/1.1 only, but this is what I got from PHP site:
 ?php
 header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1
 header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past
 ?

 Tijnema

 --
 Vote for PHP Color Coding in Gmail! - http://gpcc.tijnema.info

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
Vote for PHP Color Coding in Gmail! - http://gpcc.tijnema.info 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is it possible to stop an image from being cached?

2007-07-26 Thread Tijnema

On 7/27/07, Dan [EMAIL PROTECTED] wrote:

Is this header you're refering to the header of the page which contains the
image, or the image itself?

- Dan


The image itself.

Also note, that if you use my solution 2, you still might get
problems, as the page that is calling might be cached, and in the
cached page, it refers to the image with the same unique code, and it
will use the cached image again.

Also, if you use solution 2, the image will still stay forever in the
temp folder of the browser(unless the user is cleaning it). If you use
solution 1, the browser will keep it only for this page, and will
remove it afterwards.

Tijnema


Tijnema [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On 7/27/07, brian [EMAIL PROTECTED] wrote:
 Tijnema wrote:
  On 7/26/07, Dan [EMAIL PROTECTED] wrote:
 
  I have a situation where there is a single image let's call it
  somebody.jpg.
  I want to be able to dynamicly create this image using php, basicilly
  I have
  PHP set to handle .jpg files also, so I then go through and create an
  image
  based upon some info I get from a database call and then use
  header('Content-Type: image/jpeg');
  passthru($file);
  to send the image to the user.
 
  My problem is once they view the image their browser helpfully
  caches it
  so they don't have to download it again.
 
  Is there any tactic short of changing the name constantly of the image
  to
  avoid browser caching of an image?
 
  - Dan
 
 
  Solution 1:
  Send a header() that avoids caching (can't remember it exactly)

 You can try:

 header('Cache-Control: no-store, no-cache, must-revalidate,
 Post-Check=0, Pre-Check=0');

 brian

 That's HTTP/1.1 only, but this is what I got from PHP site:
 ?php
 header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1
 header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past
 ?

 Tijnema

 --
 Vote for PHP Color Coding in Gmail! - http://gpcc.tijnema.info

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
Vote for PHP Color Coding in Gmail! - http://gpcc.tijnema.info

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is it possible to stop an image from being cached?

2007-07-26 Thread Tijnema

On 7/27/07, brian [EMAIL PROTECTED] wrote:

Tijnema wrote:
 On 7/26/07, Dan [EMAIL PROTECTED] wrote:

 I have a situation where there is a single image let's call it
 somebody.jpg.
 I want to be able to dynamicly create this image using php, basicilly
 I have
 PHP set to handle .jpg files also, so I then go through and create an
 image
 based upon some info I get from a database call and then use
 header('Content-Type: image/jpeg');
 passthru($file);
 to send the image to the user.

 My problem is once they view the image their browser helpfully
 caches it
 so they don't have to download it again.

 Is there any tactic short of changing the name constantly of the image to
 avoid browser caching of an image?

 - Dan


 Solution 1:
 Send a header() that avoids caching (can't remember it exactly)

You can try:

header('Cache-Control: no-store, no-cache, must-revalidate,
Post-Check=0, Pre-Check=0');

brian


That's HTTP/1.1 only, but this is what I got from PHP site:
?php
header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past
?

Tijnema

--
Vote for PHP Color Coding in Gmail! - http://gpcc.tijnema.info

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is it possible to stop an image from being cached?

2007-07-26 Thread Richard Lynch
On Thu, July 26, 2007 6:32 pm, Tijnema wrote:
 Also, if you use solution 2, the image will still stay forever in the

Not forever.

Just until something else being downloaded shoves it out due to the
folder size restriction.

The browser might even be smart and keep oft-used resources in the
cache in favor of others rather than be strictly FIFO.

So a random URL makes browsers that were dumb enough to cache
something they shouldn't have cached (if you sent no cache headers)
clog up their cache with the un-re-usable files that it shouldn't
have saved anyway.

Oooh, hurt me. :-)

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is it possible to stop an image from being cached?

2007-07-26 Thread Richard Lynch
On Thu, July 26, 2007 4:56 pm, Dan wrote:
 Is there any tactic short of changing the name constantly of the image
 to
 avoid browser caching of an image?

You can try to use all the zillion header calls people will send you.

Somewhere out there is a really stupid browser that will insist on
caching it.

src=somebody.jpg??php echo uniqid()? will make it very difficult
for any halfway-decent browser to cache.

However, that can lead to some issues when the URL of the image is
embedded elsewhere, as some folks will strip off the GET arg on the
assumption that it's invalid for a JPEG.

Embedding the random bit so that it LOOKS like a directory, but isn't,
will avoid that problem.

I blogged about how to do this kind of thing (in another context) over
here:
http://richardlynch.blogspot.com/2006/06/php-downloads-content-disposition.html

There are shorter / better explanations out there, but I don't know
where without Googling, and you know how to Google, right?

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Is it possible to stop an image from being cached?

2007-07-26 Thread Chris Aitken
 header('Cache-Control: no-store, no-cache, must-revalidate,
 Post-Check=0, Pre-Check=0');

 brian

That's HTTP/1.1 only, but this is what I got from PHP site:
?php
header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT); // Date in the past
?


But wouldn't that make every image on the page be uncached and reloaded each
time? Not very efficient if the shell of the site keeps getting loaded if
only 1 or 2 images need to be forced.




Regards
 

Chris Aitken
The Web Hub Designer and Programmer
Phone : 02 4648 0808
Mobile : 0411 132 075
 
-
 
Making The Web Work The Web Hub
http://www.thewebhub.com.au/
[EMAIL PROTECTED]
 
-
 
Confidentiality Statement:  
This message is intended only for the use of the Addressee and may contain 
information that is PRIVILEDGED and CONFIDENTIAL.  If you are not the 
intended recipient, dissemination of this communication is prohibited.  
If you have received this communication in error, please erase all 
copies of the message and its attachments and notify us immediately.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php