-3

I want to protect my url .mp4 amazon s3 to be able to insert it in my player on my site. I would like to get one thing:

https://[mysite]/encrypt/encriptar.php?v=M3BtRGtUNkRoSndYRU5PdWI0Tmd2SjUrUmZRWWxybFVGU2pCTHBkT3B0U1Fkd3JsN2RaQXFQYURYdjVUL1g2bk1KQTkvcUZKbUY3UTRvOVNSNzNtbks3NUl6TzlZVFdHbXFKT1ZQUVNvOU9ndS9CTnowYmVqVWk4dXA4dzk0L0xVOStlb1Y5UTFsaU1RTmVKUUFUd2VRPT0=

I found this script but it does not seem to work, it does not play the video:

    <?php
    session_start();
    $sid = session_id();

    $path = "http://s3-us-east-1.amazonaws.com/my bucket/myfile.mp4";

    $hash = md5($path.$sid);

    $_SESSION[$hash] = $path;

    ?>

    <html>
<head></head>
<body>

    <video width="320" height="240" controls>
        <source src="encriptar.php?video=<?= $hash ?>" type="video/mp4">
    </video>

</body>
</html>
lebelinoz
  • 4,890
  • 10
  • 33
  • 56
evil1990
  • 1
  • 2

1 Answers1

1

When someone visits that page they will try to play the video by visiting that page again. It's a cycle.

Do this in encriptar.php:

<?php
session_start();
$sid = session_id();

$path = "http://s3-us-east-1.amazonaws.com/my bucket/myfile.mp4";

$hash = md5($path.$sid); //You need to use proper encryption. This is not secure at all.

$_SESSION[$hash] = $path;
?>

<html>
<head></head>
<body>

    <video width="320" height="240" controls>
        <source src="decrypt.php?video=<?= $hash ?>" type="video/mp4">
    </video>

</body>
</html>

This should be your decrypt.php

<?php 
session_start();
if (isset($_GET["video"]) && isset($_SESSION[$_GET["video"]])) {
   header("Content-Type: video/mp4");
   $file = $_SESSION[$_GET["video"]]; //Get the filename
   readfile($file); //Proxy
   die();       

}

This way your encryptar is creating a hash to a decryption script that will decrypt and proxy the file. Note that everyone can still download the video, the only thing this protects you against is people figuring out your bucket name.

apokryfos
  • 38,771
  • 9
  • 70
  • 114
  • i tried as you said i see this but the file does not play appears invalid source why? – evil1990 Sep 18 '17 at 16:05
  • OK the video works, but if I move the player forward half video example video hangs to forward and back the player I have to wait for all the buffering to be full. without script the video works perfectly.   you have a solution for this   thank you so much – evil1990 Sep 18 '17 at 23:15
  • 1
    @evil1990 that's much more complex. Check https://stackoverflow.com/questions/15797762/reading-mp4-files-with-php – apokryfos Sep 18 '17 at 23:29