-1

I want to protect files by query key in PHP. For example:

http://example.com/file.mp4?key=sdkjhslkdjvkjbvs

If the query key is in the database, let to download and read file if not forward location.

How can I do this?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116

1 Answers1

0

You can redirect .mp4 to .php (without url changing). Something like this:

RewriteRule ^(.*).mp4?key=(.*)$  /video/test.php?key=$2&file=$1

After this you can catch $_GET['key'] and check your database - if ok you can throw you file for downloading

if(file_exists($file_link)){
    header("Content-type: application/octet-stream");
    header("Content-disposition: attachment; filename=/".$file_link);
    echo readfile($file_link);
}