Can I detect if the web browser is requesting a certain image from the server? I want to check if the user downloads the image or if it is already cached from its browser.
The main idea:
I am counting unique visitors per profile page. I use IPs
and Cookies
for now but want to add this, too. IP
could be changed easily, Cookie
could be blocked/deleted.
My idea is to use this information just like a flash cookie
. The image will be 1px x 1px
in size and will be invisible to the user. I don't have experience with ActionScript and Flash at all, so I can't use flash cookie
and want to try with this.
EDIT:
As I understand from Sven's answer maybe I couldn't explain what I need. My question is same as Sven's answer. How to wait for the request to appear on the server
? I want the browser to cache the image, so it will be downloaded only if the user is an unique visitor, i.e. he is viewing the page for the very first time.
I want to get this information and check if the image is requested or not (i.e. it is cached). Something like:
$requested_files = $_SERVER['REQUESTS']; // Or something similar, this is the question.
$file_name = $profile_page_owner_id.'.png'; // For example.
if(in_array($file_name, $requested_files)) {
// File is requested, so it is not cached. This is an unique visitor.
// Of course except this I will continue to check IP and Cookie.
// This will be the 3rd check.
} else {
// File is not requested, so it is already cached.
// Page is viewed before, this is not an unique visitor.
}