Forum Moderators: coopster
The important part is that I need to ensure PHP does actually create the image and the cookie only when the image creation is successful.
A real world example of PHP images can be seen as the avatars of vBulletin PHP based forum software.
I have absolutely no idea of how to approach this but it is a very high level goal of mine.
- John
I use something similar on my site to track visitors when they visit static HTML pages, not PHP pages. On these HTML pages there is a PHP generated image and at the same time the script sets a cookie for visitor tracking.
So in short the following things are done:
- Create image internally
- Send cookie
- Output image data
Don't hesitate to ask me if you need more detailed information.
Regards,
Arjan
I found this...
[us3.php.net...]
I'll be trying that out a little later (I have to go out to a client of mine this morning firs though).
I have no materials, just trying to get some direction with this. My server and my local copy of Apache support GD.
I'm not working on any uploader nor will use any in conjunction with this.
The image will already be on the server, it's a sort of conditions test for a specific page. If the condition passes the cookie is set...that is if the image displays correctly.
I'll have more time to post stuff I'll be messing around with after I get back from my client.
Thanks to Arjan as well ... for both your responses.
- John
I'm not working on any uploader nor will use any in conjunction with this.The image will already be on the server, it's a sort of conditions test for a specific page. If the condition passes the cookie is set...that is if the image displays correctly.
Then, you just need to check if the file exist in PHP
<?php
$filename = '/path/to/foo.img';if (file_exists($filename)) {
echo "The file $filename exists";
// SET COOKIE
} else {
echo "The file $filename does not exist";
// DO NOT SET COOKIE
}
?>
or another way (not sure) would be to use the getimagesize function
<?php
$filename = '/path/to/foo.img';
if (getimagesize($filename)) {
@$file_width = $sizeb[0];
@$file_height = $sizeb[1];
echo "The file $filename exists";
// SET COOKIE
} else {
echo "The file $filename does not exist";
// DO NOT SET COOKIE
}
?>
I'm not trying to detect the image on the server but rather if the user requested and successfully downloaded the image.
If the user requests the image and it successfully downloads then I wish to set a cookie.
Thats it, I don't need the cookie code, else code, etc. I just need the PHP script to reliably know if the user is capable of viewing images via PHP. Thanks for your continued help!
- John
I AM MAY BE WRONG, but since PHP is a server-side script, checking if the image has been correctly downloaded using PHP is difficult if not impossible...
Furthermore, as you may know, cookie should be sent before any content or HTML, so sending a cookie after the image is dowloaded is also difficult....
UNLESS you work with HTTP request (I am not good at header request, therefore I can't help you) but I guess there is a way to request a download, check if dowloading has been succesfull and sent further header request and cookie.
If you have a real example at vBulletin PHP, why don't you download the bulletin board and do some search in the script itself to locate how they are doing?
Arjan said that he is currently using something similar, may be you could get in touch with him. And lastly, if you find the solution, report back.
Tomda
John already stickied me and I mailed him the following example:
In each HTML file have an IMG tag somewhere in the body like:
<img src="testimage.php" alt="">
And a PHP file called testimage.php with the following content:
<?
set_cookie(cookie stuff);
$ImageOnServer = "ImageToServe.png";
$Fsize = filesize($ImageOnServer);
$fp = fopen($ImageOnServer,"r");
header('Content-type: image/png');
header('Content-Length: ' . $Fsize);
fpassthru($fp);
fclose($fp);
?>
When someone/something reads the HTML file and does not request the image (a PNG in my example), the cookie won't be set. If it does request the image, so a genuine user with a genuine browser, the cookie will be set. This cookie wiil then be sent when the next file is requested by the user.
*Drumroll*
Technical!
I used a jpg image and modified the mime as so (image/jpeg). It set the cookie and displayed the image.
Next I had to ensure that the image would not load if I disabled images in the browser. Image still downloaded (but the images on my site including via the CSS did not download).
I need a different means of testing this though I'm not sure how.