I am developing a joomla media website for the iphone with php. The media server I am using is powered by wowza. The final step I need to do is secure the stream with aes-128. To do this I need to distribute the key to users who are logged in to joomla. there are two parts to the code one launches the propper joomla infrastructure to access the DB and the if else statement is supposed to distribute the key. From my research I have found that the following code is needed to be able to get user info from joomla:


define( '_JEXEC', 1 );

define('JPATH_BASE', dirname(__FILE__) );

define( 'DS', DIRECTORY_SEPARATOR );

require_once JPATH_BASE.DS.'includes'.DS.'defines.php';

require_once JPATH_BASE.DS.'includes'.DS.'framework.php';

jimport( 'joomla.application.application' );

require_once ( JPATH_BASE .DS.'includes'.DS.'application.php' );

$mainframe =& JFactory::getApplication('site');

$mainframe->initialise();

$jUser = &JFactory::getUser();

$usr_id = $jUser->get('id');

I have defined a couple of variables to get the user id and in the next code I created an if else statement to verify if a user id present.

function hex2bin($h)
{
        if (!is_string($h))
                return null;
        $r = '';
        for ($a=0;$a<strlen($h);$a+=2)
        {
                $r .= chr(hexdec($h{$a}.$h{($a+1)}));
        }
        return $r;
}


if ($usr_id)
{
	header('HTTP/1.0 403 Forbidden');
}
else
{
	header('Content-Type: binary/octet-stream');
	header('Pragma: no-cache');


echo hex2bin('865D26D502D3E31C67EABEDE6730A53D');

exit(); // this is needed to ensure cr/lf is not added to output
}

Problem is I have verified the if else statement with simple redirects and it works perfectly but when I replace the simple redirects with the key distribution statements it no longer works. The php seem to be working but the player will not play the file. Here is the original code provided by wowza:

<?php

function hex2bin($h)
{
        if (!is_string($h))
                return null;
        $r = '';
        for ($a=0;$a<strlen($h);$a+=2)
        {
                $r .= chr(hexdec($h{$a}.$h{($a+1)}));
        }
        return $r;
}

$isValid = true;
if (! $isValid)
{
	header('HTTP/1.0 403 Forbidden');
}
else
{
	header('Content-Type: binary/octet-stream');
	header('Pragma: no-cache');


echo hex2bin('DE51A7254739C0EDF1DCE13BBB308FF0');

exit(); // this is needed to ensure cr/lf is not added to output
}

?>

This works fine on its own by changing $isValid to true or false but I would like the if else statement to be based on the joomla variables. Any help with this will be greatly appreciated.

    Write a Reply...