Random video at static URL
-
27-09-2019 - |
Question
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
Solution
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)]);
OTHER TIPS
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow