Announcement

Collapse
No announcement yet.

PHP Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    PHP Help

    Hi all,

    I have to have a secret key and call some PHP to serve up some videos for a members-only section of my Actinic website. It's actually very, very simple to get the embedded players to work on my site, all I have to do is put the html (which is generated by the company where my playlist/videos are) inside a product with a customised, description-only template. These products are within Members-only sections (or the products themselves are marked in price schedule as members-only to view) and that serves them up fine for anyone who logs in, what I am after is secure content and this gives it but i am not 100% sure how to implement it? The Pearl Script that needs to work on the server is this:

    <?php

    /**
    * This PHP function will generate a signed URL. Parameters:
    *
    * $path The path of the video or player you want to sign, e.g. "videos/KsoieJsu-123.mp4"
    * Note this excludes the domain and excludes the trailing slash.
    * $secret The API secret of your account, e.g. "Jau8Ya71hakdpF0A".
    * This acts as a shared secret between your server and BOTR.
    * $timeout The time in seconds you want the signed URL to remain valid, e.g. "3600".
    * Typical timeouts are between a minute and a few hours. Default is "3600".
    * Make sure the time on your server is set correctly, or URLs with short timeouts will fail!
    * $domain The masked domain name you want to use for signing the content, e.g. "video.mysite.com".
    * Use this if you have setup DNS masking. Defaults to "content.bitsontherun.com".
    **/
    function get_signed_url($path,$secret,$timeout,$domain) {
    if($900) {
    $expires = time() + $timeout;
    } else {
    $expires = time() + 3600;
    }
    $signature = md5($path.':'.$expires.':'.$secret);
    if($domain) {
    $url = 'http://'.$domain.'/'.$path.'?exp='.$expires.'&sig='.$signature;
    } else {
    $url = 'http://content.bitsontherun.com/'.$path.'?exp='.$expires.'&sig='.$signature;
    }
    return $url;
    };

    ?>

    I have the details here which need to be swapped/added to the above:

    My player ($path) =mJ3P0RJI-z1I3pcbB.js
    My ($secret) = xxxxxxxxxxxxxxxxxxxxxxx
    My ($timeout) = standard=3600 I had 900 (this is seconds)
    My ($domain) = content.bitsontherun.com

    I need someone's help as I'm not very good with this sort of thing, I can get it but just not 100% sure which bits to change. Once I see it I will understand better.

    Here is a snippet from the documentation:

    If you want to secure your content, but still want to embed players or offer video downloads on your own site (e.g. if you have a pay-per-view site), then you should implement a small script on your site that automatically generates the signed links. For example, you could use a small PHP function like this one to always generate a valid signed URL:


    Code:
    <?php
    function get_signed_player($videokey,$playerkey) {
      $path = "players/".$videokey."-".$playerkey.".js";
      $expires = round((time()+3600)/60)*60;
      $secret = "Ksi93hsy38sjKfha9JaheEMp";
      $signature = md5($path.':'.$expires.':'.$secret);
      $url = 'http://content.bitsontherun.com/'.$path.'?exp='.$expires.'&sig='.$signature;
      return $url;
    };
    
    echo "<p>Watch this cool video:</p>";
    echo "<script type='text/javascript' src='".get_signed_player('nPripu9l','ALJ3XQCI')."'></script>";
    ?>
    Not sure what the echo part of the code is above? Does that then have to be on the page? I've asked for more help from the site but haven't really gotten what I needed. Just pointed towards this . . a bit stuck now.

    If I understand this correctly, I will need this file on the server but not sure what it should be called?

    I'm sorry if this is a bit complex, more than usual, but I'm 99% of the way to offer full tutorials and my own d-loads of videos and supporting files, right from the site and this has caused me a bit of a stumbling block.

    Thanks for any help anyone can offer on this.

    Sincerely

    Brian
    Organic Image - Award-winning Airbrush Kustom Art & Airbrush Classes

    #2
    Originally posted by BrianCurtis View Post
    If I understand this correctly, I will need this file on the server but not sure what it should be called?

    I'm sorry if this is a bit complex, more than usual, but I'm 99% of the way to offer full tutorials and my own d-loads of videos and supporting files, right from the site and this has caused me a bit of a stumbling block.

    Thanks for any help anyone can offer on this.

    Sincerely

    Brian
    PHP can be run on the server or it can be embedded into the html. The last snippet can be saved as a PHP file on the server when run the two echo commands will add the code into the browser so that it displays the text Watch this coolVideo, and the second link will generate some code that will run a javascript file the name of which is generated by the function get_signed_player(....).

    To use this you would have to include code in the html file that will run the php script using the name that you have used to store the script.

    The first script also generates a link to a file that includes an expiry time that will be processed by the code in that file, in this case a javascript file.

    For the first script is just a function that needs to be called from other code that will pass in the necessary parameters and make use of the url returned.

    Code:
    $path = "mJ3PORJI-z1I3pcbB.js';
    $secret= "xxxxxxxxxxxx"; 
    $timeout = 3600; 
    $domain = "content.bitsontherun.com;
    
    $myurl =  get_signed_url($path,$secret, $timeout,, $domain);
    This sets the variable $myurl to the URL of a javascript file including parameters relating to timeout, but you need more code to actually use this and that really depends on what is in the html they are providing.
    Last edited by malbro; 15-Oct-2010, 01:31 PM. Reason: spelling

    Malcolm

    SellerDeck Accredited Partner,
    SellerDeck 2016 Extensions, and
    Custom Packages

    Comment

    Working...
    X