1

I have a laravel website on shared hosting and some videos on a cloud storage.

What do I need to hide direct links and stream videos on my website?

The videos are for sell and somebody might download them without paying. so every time that a user wants to see a video, I generate a random link and use it in video src. I generate random string and pass it to a function. The function finds video link and uses curl to get and play video (PHP stream remote video file) but it's not good enough. If it is possible to stream videos from another source, what do I need to do it right?

Do I need a streaming server? is apache good enough? what should I learn?

  • Hi Reza, Welcome to stack overflow, and congrats on your first question. At the moment it's a bit broad and confusing, and it seems like what you are trying to do is a bad idea. Can you explain in more detail why you are trying to get rid of direct links, and what you have tried so far? – Tim Ogilvy Mar 13 '19 at 22:38
  • 1
    Thanks for your attention. I am trying to hide direct links because the videos are for sell and somebody might download them without paying. so every time that a user wants to see a video, i generate a random link and use it in video src. (excuse me for my english) – Reza Ghasemi Mar 13 '19 at 22:47
  • Ok that's really good, but you will need to add this information by editing your question to make it clearer. Help people answering your question understand the problem you are trying to solve. – Tim Ogilvy Mar 13 '19 at 22:52
  • I think apache will be fine, about hiding files reference [this question](https://stackoverflow.com/questions/2679524/block-direct-access-to-a-file-over-http-but-allow-php-script-access) – Runner Mar 13 '19 at 22:58
  • 1
    Sorry, you are right @Tim Ogilvy. i edited the question. – Reza Ghasemi Mar 13 '19 at 22:59
  • Hi Reza, unfortunately there's no real way of hiding the URL, one thing you could do is create a PHP file that streams the video. But even then, anyone with network monitoring app like Wireshark would know the actual origin location of the file. for performance purposes I suggest VideoStream.php (https://gist.github.com/ranacseruet/9826293). for future posts please consider adding more information or link to your code so we would be able to help you better – Ramin Ahmadi Mar 13 '19 at 23:01
  • I think apache will be fine, about hiding files reference [this question](https://stackoverflow.com/questions/2679524/block-direct-access-to-a-file-over-http-but-allow-php-script-access) – Runner Mar 13 '19 at 23:02
  • Thank you @Runner. videos are on a cloud storage and I cant use htaccess. – Reza Ghasemi Mar 13 '19 at 23:12
  • Thanks @Ramin Ahmadi. I think that would be enough to just hide the links from users with no programming skills. I am trying to stream videos with better performance and I don't know if it is possible. – Reza Ghasemi Mar 13 '19 at 23:15
  • How much control do you have over the webserver? If you use Nginx, Laravel will automatically take advantage of [X-Accel](https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/) for files served using `response()->file('/path/to/file')`, allowing Nginx to stream files from an internal directory after Laravel has authenticated the request, and free up the PHP process. – Travis Britz Mar 14 '19 at 00:34
  • Thanks @Travis Britz. right now it's shared hosting, but I can prepare a server. can I use response()->file('/path/to/file') for remote files? – Reza Ghasemi Mar 14 '19 at 05:56
  • You would have to download the file to the server first before streaming (which you have to do anyway). Otherwise you would need to be using a cloud storage provider that offered temporary urls and could serve the files – Travis Britz Mar 14 '19 at 12:52
  • Thank you @Travis Britz. it seems there is no way to stream a remote video. – Reza Ghasemi Mar 15 '19 at 06:53

0 Answers0