Closed Thread Icon

Topic awaiting preservation: prevent an image from being cached. Pages that link to <a href="https://ozoneasylum.com/backlink?for=25402" title="Pages that link to Topic awaiting preservation: prevent an image from being cached." rel="nofollow" >Topic awaiting preservation: prevent an image from being cached.\

 
Author Thread
GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 04-02-2005 13:39

hello,
to fight spambots throughout my website, i use an common technique to prevent forms from being filled out automatically.

a php-script generates a jpg with a number which has to be validated in the form.
the image is generated new each time the page is called.
now the problem is that some browsers (opera) seem to cache this image and therefore the validation process doesnt work anymore.

here is the code i use:

$i=imagecreatetruecolor(50,20);
$r=rand(10000,99999);
imagestring($i, 4, 4, 2, $r, imagecolorallocate($i, 255, 255, 255));
imagejpeg($i,"/antispam.jpg");

then i just use the image-tag to put it on the site.


is there a way to force this image to be reloaded on every pageload without putting the no-cache headers?

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-02-2005 13:56

If you don't mind to use a bit of JavaScript, you could add a random parameter in the SRC attribute of the image tag, to make sure it reloads it.

Unless the cache of the browser is really hungry, setting the HTTP headers related to cache and expiracy time should be enough to force the browser to not cache the HTTP flux ( the image ).



(Edited by poi on 04-02-2005 13:57)

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 04-02-2005 14:09

a random parameter?

like

img src="i.jp" param="123"

i could do this with php too.

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-02-2005 14:12

I rather thought to : antispamImageGeneratedInPhp.jpg?randomParameter=165781379
but you could also generate a completely random src and catch the error 404 to output your anti spam image.

Using JavaScript you'll be sure that even if the page is cached, the antispam image will be different.




(Edited by poi on 04-02-2005 14:14)

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 04-02-2005 14:37

ok thanks!

you mean, that if the page is completely cached, that a php-random parameter would also be cached?

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-02-2005 14:43

yep

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 04-03-2005 13:05

ok, i did it so and it works. thank you poi.

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-03-2005 13:27

you're welcome

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 04-05-2005 06:04

You can also do this with meta tags, of course there are a few things u need to do to get it working in most browsers.

Take a read here: http://www.htmlgoodies.com/beyond/reference/article.php/3472881

« BackwardsOnwards »

Show Forum Drop Down Menu