views:

24

answers:

2

I need to provide a static url to a client, eg. http://domain.com/video.mp4. However this URL needs to provide a random video from a selection of 5 videos each time it is accessed.

Is this possible using PHP and mod_rewrite? Or some other way?

Thanks

A: 

Does your client require the url to end in .mp4?

If not you could indeed use a mod_rewrite by selecting a random number from, say, 1 to 5

Argote
A: 

You may be able to provide a url to a PHP script (http://domain.com/video.php), which then sets its content-type header to the type of a video and then randomly reads out a file using readfile.

I don't think you need to use mod_rewrite in this case.

header('Content-type: video/mp4'); // I don't know the correct MIME type
$files = array('vid1.mp4', 'vid2.mp4', 'vid3.mp4');
readfile($files[array_rand($files)]);
Ryan Kinal
Cool, so I should be able to add: "AddType application/x-httpd-php .php .mp4" to my .htaccess and all should work well... Thanks!
bradleyg