Page 1 of 1

Setting a Cookie in an image file?

Posted: Wed Nov 26, 2008 1:09 am
by vectorfrog
Hi I'm using a separate php image file to return a dynamic image. I'd like to return some values along with the image in a cookie. Is this possible to do? Every time I try to write a cookie in the image file, nothing happens. Here's the code I'm using:

Code: Select all

setcookie("image_ratio", $ratio, time()+3600);


Am I running into problems because I declare the content type as an image in a header?

Code: Select all

header('Content-type: image/png');
If so, is there any way I can pass those values?

For those who want to see the application you can check it out at:

http://www.vinylletteringdecor.com/cust ... tering.php

I'm trying to pass the ratio of the height and width of the text string (pulled from the bounding_box) so I can give an accurate width, because the approximate width can be WAY off depending on the font being used. Any help would be great. Thanks

Re: Setting a Cookie in an image file?

Posted: Wed Nov 26, 2008 2:58 am
by requinix
I'm pretty sure you can set a cookie too - it's an HTTP request, same as for webpages.

Are you calling setcookie before you output the image, or after? Because one is right and one is wrong, and guess which of the two I italicized.

Re: Setting a Cookie in an image file?

Posted: Sun Dec 07, 2008 9:28 am
by vectorfrog
Thanks, that was exactly the issue. Your italicized instructions have my project back on track! :D