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



Question:

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 http://121.125.77.146  DEBUG: CPlayerCoreFactory::GetPlayers(http://121.125.77.146/cgi-bin/sbview.cgi?systype=10000&subtype=4&id0=17678&id1=27635&id2=368507&id3=285792&nodeid=3071517&userno=0&userid=&level=1&part=0&ispay=0&mkey=2bd5454e93890a8ae2fe76948764a2d6&skey=5176153017445b5b79f897eec711996b&dummy=1279941981&title=%5bStar2Gether%5d%20%c0%cc%ba%a5%c6%ae%c0%fc_1%ba%ce&impurl=&TVINFO=10000,4,17678,27635,368507,285792,)  

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


Solution:1

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.


Solution:2

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
Previous
Next Post »