Joomla Session Handling within External PHP page

You can't read the Joomla session within external php file in the same application (in the Ajax file or external url request)
To short out this issue, you have include the following code in the top of your file. (you can copy all the folloing code and create a session.php file and can include in each file you needed, if you need to use repeatedly.)


session_start();
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', dirname(dirname(dirname(__FILE__))) );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$session =& JFactory::getSession();
$user = $session->get( 'login'); //login is the session name

If you set the session in the external page, we cant read that within joomla page.(I tried it did not work for me)
So, include the page within the joomla article and set the session within the joomla as follows. then can read it externally as described above.
1. include a page within joomla article (test.php)
2. Set the session as follows within the test.php file
$session =& JFactory::getSession();
$values = array('uname'=>'thowfeek','password'=>'abc123');
$session->set( 'login',$values);