Jump to content


Photo

GD Image Issue


  • Please log in to reply
3 replies to this topic

#1 crimsonmoon

crimsonmoon
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 30 June 2006 - 02:11 PM

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.

$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);

imagepng($image);
imagedestroy($image);

I call this page by doing this:

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

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?


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 30 June 2006 - 03:30 PM

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
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 crimsonmoon

crimsonmoon
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 30 June 2006 - 04:00 PM

I tried adding the header...I do something with it I just didn't show it.

THX!

#4 crimsonmoon

crimsonmoon
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 04 July 2006 - 12:23 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users