0
votes

I'm trying to get session variables working with Joomla using their session code since php's sessions don't work. I am running into a problem trying to access session variables within the joomla custom code module editor though. When I try to access the session variable using the code:

define( '_JEXEC', 1 );
define('JPATH_BASE', "../");
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
$session = JFactory::getSession();
$print $session->get('status');

I get nothing. If I take that same code and paste it into its own php file I can get the status variable fine. When I look at the plain text version of Joomla preview I see this:

get('status'); ?>

Doing some testing I think it's related to the '->' operand. Has anyone encountered this before and know how to fix it? I'm running Direct PHP and can print out strings and other variables inside of the module fwiw.

1

1 Answers

0
votes
  1. you can't run PHP (or Javascript!) in Joomla articles without installing a plugin that supports it. I recommend using: http://www.kksou.com/php-gtk2/Joomla/DirectPHP-plugin.php
  2. change $print to print

Try to comment out all the preceding lines and see if one of the "includes" is messing up the page:

/*define( '_JEXEC', 1 );
define('JPATH_BASE', "../");
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
*/
$session = JFactory::getSession();
print $session->get('status');