Is it possible to save a cookie on a user computer when he loads an image from my server?
So let's say my image url is: http://www.site.com/image.jpg
If he loads just that jpg, can I save a cookie on his machine?
Thanks,
You will have to serve the image through a PHP script if you want to use PHP for this. This may be done by rewriting the request to go to a PHP file, and then use readfile in that script.
Another solution is to set the cookie directly in your web server. How you do that depends on the web server you are using. This is how you do it in Nginx:
location /image.jpg {
add_header Set-Cookie "cookiename=value";
}
And for Apache:
<FilesMatch "^image\.jpg$">
Header set Set-Cookie: "cookiename=value"
</FilesMatch>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With