easiest way is to check the referer $_SERVER['HTTP_REFERER']
. But this can be falsified.
More secure is using some kind of authorization, i.e.
You give every client allowed to see this picture an unique secret key (or salt).
Then your client must create a standardized time string like 20100701170821
.
Then your client can do something like this:
<?php
$public_identifier = "yourclient.com";
$secret = "1234567890ABCDFGHIJKLMNOPQRSTUVWXYZ";
$time_string = date("YmdHis");
$signature = hash_hmac('sha256',$time_string,$secret)
$url_to_access_the_images += "?time=$timestring&signature=$signature&client_id=$public_identifier"
?>
this will generate an URL like this:
yourdomain.com/secret_image.php?time=20100701170821&signature=e9de9112433944188b5da9fa7157bf167bfdd6af95120aea2674424838154ea9&client_id=yourclient.com
On your site you can do the checking like this:
<?php
$secret = get_secret_for_client_id($_GET['client_id']);
// check if the request time is within a tolerance of 15 minute
// time difference between client server and your server
// and check if he's authorized (signature is valid).
if(abs(int($_GET['time']) - int(date("YmdHis"))) < 1500) &&
$_GET['signature'] == hash_hmac('sha256',$_GET['time'],$secret)) {
// do what ever you do to ouput the picture
} else {
// do what ever you do for unauthorized access.
}
?>