Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to serve .flv files using PHP?

I'm building a streaming video site. The idea is that the customers should pay for a membership, login to the system, and be able to view the videos. I'm going with FlowPlayer for showing the actual videos.

The problem now is, the videos need to be stored somewhere publically and the url to the .flv files needs to be passed to flowplayer for it to be able to show them. This creates a problem because anyone can do a view source, download the video, and distribute it all across the internet.

I know some people serve images using php by doing an image header() and then they can do something like:

<img src="image.php?userId=1828&img=test.gif" />

The php script validates the user ID and serves up the .gif and the actual url of the gif is never revealed.

Is there anyway to do this with .flv or any other video format also? E.g, the file and user ID passed onto the PHP script, it validates them, and returns the video?

like image 494
Ali Avatar asked Mar 01 '09 08:03

Ali


1 Answers

You can set up a directory containing the FLV files on your webserver that can only be accessed by PHP, then in your PHP script you can authenticate the user as usual and simply send a header to the browser telling it to expect an FLV, then echo the raw FLV data:

<?php
// here is where
// you want your
// user authentication

if ($isAuthenticated)
{
  header("Content-type: video/flv");
  echo file_get_contents($pathToFLV);
}
?>

As Chad Birch discussed, this will only prevent people from linking directly to the video - you can't prevent piracy this way.

like image 73
clawr Avatar answered Oct 03 '22 23:10

clawr