connorjrt
connorjrt

Reputation: 7

Disable direct access to file, but still allow it to be embeded

I'm currently making a website with videos on it, however, I want to avoid as much as possible people being able to download them (I know that this is not 100% achievable, but there are ways to make it harder).

Here's my filesystem

- main folder/
  - watch.php
  - videos/
    - .htaccess
    - example video.mp4
    - streamer.php

And here's my code
Watch.php:

<video src="videos/streamer.php"></video>

streamer.php:

<?php
       $stream = new VideoStream("example video.mp4");
       $stream->start();
?>

.htaccess:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} ^https?://(www\.)?([^/]+)/.*$ [NC]
RewriteCond %2#%{HTTP_HOST} !^(.+)#(www\.)?\1$ [NC]
RewriteRule \.(php|mp4)$ - [F,L,NC]

Additional: The server is running loacally, and such does not have a domain name.

The video streams fine from watch.php but if you open the video source (streamer.php) you will be allowed onto the page, where you can then download the content.

What I want to happen is for the video to stream fine to watch.php but if you open streamer.php you are blocked from seeing the content.

Can anyone help me with this? I've tried just about every solution I've looked up and I can't manage to get any to work. Thanks

[EDIT]: Most preferably, this would be done in the .htaccess file so that I can also block people from entering example video.mp4

Upvotes: 0

Views: 475

Answers (0)

Related Questions