Update:
Example:
http://www.pitgroup.nl/demo/protect/?file%5Fid=1&user%5Fid=1&file=string
The file=string, does not work, because it is not correct with the database value;
The page then shows a link with the correct database value which you can click to view the hidden file. The link you clicked is still at the top then, but it will not work again. The bottom of the page shows the update database value, which is a valid link again.
To prevent hotlinking, you should actually use htacces i think.
You should do like this:
( or something like it )
mysql:
files:
id
url
created
user_files:
id
user_id
file_id
string
then insert a record into user_files, using the files info, and for the string, do something like:
md5( $file->url . $file->created . $user->id );
when a user calls an url, eg:
files / fileid / sldfjsdfasduapdj123
then you reroute it to a script, that does a lookup in the database for that string, comparing the user id and file id in the record.
after the file has been looked up, md5 the string again and save the record.
provide the user with headers of the requested file, look at
http://php.net/manual/en/function.header.php
and your done :)
( i use this for a websitet that provides flv content against sms payments )