Load Joomla framework to get access to Joomla functions using PHP


You need access to for Joomla functions via PHP?
Just include the following code into your PHP script.
Don’t forget to set the correct paths to the framework files.

<?php
define( '_JEXEC', 1 );

define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../..' ));

require_once ( JPATH_BASE. '/includes/defines.php' );

require_once ( JPATH_BASE. '/includes/framework.php' );

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

$mainframe->initialise();
?>

 

For example: now you can access the Joomla session:

<?php

 $session = JFactory::getSession();

?>


Set a session variable:

$session->set('var', 'content');

 

Get a session variable:

$session->get('var');

 

Clear a session variable:

$session->clear('var');