Tutorial :How do I create a session on a server in PHP?


I am trying to make a WDTV Live plugin in linux, which plays a video from a web url.

I have a url that is parsed from html source code. The problem is that the url is playable in XBMC, but it can't be play in all the media players. I checked xbmc log, and it looks like that XBMC creates a session to the movie url. Below is log from XBMC log file.

INFO: XCURL::DllLibCurlGlobal::easy_aquire - Created session to  DEBUG: CPlayerCoreFactory::GetPlayers(,4,17678,27635,368507,285792,)  

Is it possible to do what XBMC does in PHP? Thanks


Adding on sAc's answer, you'll also need to implement an authentication system if you only want a single media player to use it, kind of like what Netflix does. AFAIK, Netflix generates a key stored in your registry that identifies your computer and uses that key to access Netflix's servers. I assume XBMC has a similar implementation where it generates a key, stores it somewhere and uses that key as the session ID.

From the URL you've given, there are two parameters where I saw keys similar to the keys I explained above: "mkey=2bd5454e93890a8ae2fe76948764a2d6&skey=5176153017445b5b79f897eec711996b" These keys are passed through the querystring (everything the ? in the URL) that could possibly identify your XBMC.

In order to reproduce this, you really won't need PHP sessions eg:

session_start();  $_SESSION['session_key'] = $_REQUEST['session_key']; // Use either $_GET or $_POST in production  if($_SESSION['session_key'] == "the_super_secret_key") { /* play video */ }  

This is a very crude example, but you can strip the sessions altogether because you're using API calls. the_super_secret_key can also be retrieved from a database to match with the session key sent.


Not sure how you are going to manipulate it but creating a session variable in php goes something like this:

session_start();    $_SESSION['var_name'] = 'session value/variable here';  

Now you can access $_SESSION['var_name'] on any page provided that you put session_start() on a page where you are using that session variable.

Note that you can remove/unset a session like this:

session_start();  unset($_SESSION['var_name']);  session_destroy();  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »