Created
September 16, 2016 10:51
-
-
Save getjump/0e2cbe60e2421fa232d2287626f9ccbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $fcount = count(glob('webms/*.webm')); | |
| $watched = []; | |
| if(isset($_COOKIE['watched'])) | |
| { | |
| $watched = json_decode($_COOKIE['watched']); | |
| } | |
| function random_string($valid_chars, $length) | |
| { | |
| // start with an empty random string | |
| $random_string = ""; | |
| // count the number of chars in the valid chars string so we know how many choices we have | |
| $num_valid_chars = strlen($valid_chars); | |
| // repeat the steps until we've created a string of the right length | |
| for ($i = 0; $i < $length; $i++) | |
| { | |
| // pick a random number from 1 up to the number of valid chars | |
| $random_pick = mt_rand(1, $num_valid_chars); | |
| // take the random character out of the string of valid chars | |
| // subtract 1 from $random_pick because strings are indexed starting at 0, and we started picking at 1 | |
| $random_char = $valid_chars[$random_pick-1]; | |
| // add the randomly-chosen char onto the end of our string so far | |
| $random_string .= $random_char; | |
| } | |
| // return our finished random string | |
| return $random_string; | |
| } | |
| function random_video() | |
| { | |
| $files = glob('webms/*.webm'); | |
| array_filter($files, function($video) { | |
| return !in_array($video, $watched); | |
| }); | |
| shuffle($files); | |
| return $files[rand(0, count($files) - 1)]; | |
| } | |
| $randomizedVideo = random_video(); | |
| $watched[] = $randomizedVideo; | |
| setcookie('watched', json_encode($watched), time()+60*60*24*365); | |
| ?> | |
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>Online and ready to view webms: <?php echo $fcount; ?></title> | |
| <link href="resources/style.css" rel="stylesheet"> | |
| </head> | |
| <body> | |
| <a href="http://webm.panagea.org<? echo random_string('abcdefghijklmnopqrstuvwxyz0123456789', 8) ?>"> | |
| <video autoplay="autoplay" loop> | |
| <source src="<? echo $randomizedVideo; ?>" type="video/webm" /> | |
| </video> | |
| </a> | |
| <!-- I've got this idea from www.csgoani.me. So, here a credits to them --> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment