Jump to content


This topic is now archived and is closed to further replies.


GD Image Issue

Recommended Posts

I run a site and every so often I'll check the user to make sure they are not a program by displaying an image using GD and have them click the button that matches the image.

Heres the image generation code.

[code]$image = imagecreate(140, 30);

$white = imagecolorallocate($image, 255, 255, 255);
$gray = imagecolorallocate($image, 210, 210, 210);
$black = imagecolorallocate($image, 0, 0, 0);

$string = "text code pulled from database here";

for ($i=0; $i<25; $i++) {
  $x1 = rand(0,140);
  $y1 = rand(0,30);
  $x2 = rand(0,140);
  $y2 = rand(0,30);
  imageline($image, $x1, $y1, $x2, $y2 , $gray); 

$size = rand(4, 5);
$x = rand(12 , 80);
$y = rand(7 , 12);

imagestring($image, $size, $x, $y, $string , $black);


I call this page by doing this:

[code] <img src=\"page.php?user=$userid\"/>[/code]

This works for the most part.

It works great for me and does great for some of my users but some are reporting that sometimes the image doesn't match up to the choices. I can't get it to do it on me so I'm thinking it could be something to do with the cache settings on their browsers.

Am I using the image correct? Any ideas on what could be causing this?

Share this post

Link to post
Share on other sites
Your image script needs header("content-type: image/png") before the imagepng() call.

Also I was under the impression that dynamic images aren't cached.

You don't seem to do anything with the "?user=$userid" either

Share this post

Link to post
Share on other sites
Well still no luck. I even redesigned my script to pull a code from the DB to display that only changes once per hour. It's working for most but I still get a small group where it doesn't.

It almost has to be a caching issue.

Any suggestions?

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.