Setting a Cookie in an image file?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vectorfrog
Forum Newbie
Posts: 2
Joined: Wed Nov 26, 2008 12:44 am

Setting a Cookie in an image file?

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Setting a Cookie in an image file?

Post 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.
vectorfrog
Forum Newbie
Posts: 2
Joined: Wed Nov 26, 2008 12:44 am

Re: Setting a Cookie in an image file?

Post by vectorfrog »

Thanks, that was exactly the issue. Your italicized instructions have my project back on track! :D
Post Reply