Web Analytics Made Easy -
StatCounter setting a cookie via image? - CodingForum


No announcement yet.

setting a cookie via image?

  • Filter
  • Time
  • Show
Clear All
new posts

  • setting a cookie via image?

    I looked through some of the FAQs, but wasn't able to find anything relating directly this my question. Basically I was curious if there's a way to set a cookie to an image. Anyone have any ideas on how to go about this?

  • #2
    I found a number of references that state the maximum size of any one cookie is 4 KB. You can not get much of an image into that size.

    Cookies that match your domain are sent by the browser to your server on every exchange of headers (this is on every page request, including refreshing a page and every new page they navigate too.) Do you really want to slow the request for a page by the amount of time it takes to send up to 4KB of data to the server each time?

    Storing anything but values and strings in a cookie is not practical. Why do you want to store an image?

    Edit: Here is an ever shorter answer - Yes you can do this, but the data is urlencoded as it must be sent as characters. Therefore, you are limited to about a 2-3 KB image size. See the following PHP code that sets such a cookie -
    PHP Code:
    if(!$content file_get_contents('img.gif'))
    'Could not read file');

    "The cookie should be set, if it was small enough to be accepted by the browser";
    Last edited by CFMaBiSmAd; Oct 10, 2006, 11:22 PM.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.


    • #3
      Maybe the value of your cookie is the name of the image, not the
      image itself?

      setcookie("TestCookie", $content, time()+3600);

      Later, when you read the cookie back, you reference that
      image from a directory that you have ...

      <img src="./images/$content" alt="" />