Session variable problem

lopezio 26 Apr, 2011
Hi
In server validation I have the following code:

session_start();
$_SESSION['username']=$username;
  global $mainframe;
  $mainframe->redirect("uploads/upload1.php");

in my file upload1.php I have the following code:

<?php
session_start();
echo " A sessão é ";
echo $_SESSION['username'];

The $_SESSION['username']; is empty. Why?
GreyHead 26 Apr, 2011
Hi lopezio,

Because $username isn't defined anywhere?

Bob
nml375 26 Apr, 2011
Hi,
It might be that Joomla implements it's own session handler (defaults to using the sql-database storage), while your standalone php-script uses the php-default handler. Have a look at the chrono_verification.php script for hints on how you can access data stored in the session storage by Joomla in your standalone script.

/Fredrik
lopezio 27 Apr, 2011
Hi Fredrik
I think you are in the right track. Joomla creates is session variables and when I execute other php files outside joomla the session variables are empty.
lopezio 28 Apr, 2011
Here is my solution to this problem.
I used jumi (and made some upload code) and all works fine now because I don't have to exit form Joomla.
wrong answer - Sorry
I have to exit from joomla with my script for upload

<?php
session_start();
//$target_path = "uploads/";
$cam= $_SESSION['username'];
$target_path = $cam."/";
echo $target_path;

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>


Lost $_SESSION['username'] value
Not solved yet
nml375 28 Apr, 2011
Hi,
The lines from chrono_verification.php that you need, are the following:
define( '_JEXEC', 1 );

/* Probably have to modify this line; make sure it points to the directory where your Joomla-installation resides
 */
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../..' ));

define( 'DS', DIRECTORY_SEPARATOR );

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();

/* Read data from the session storage;
 * Make sure you use $session->set() when you save the value in the session storage
 */
$cam = $session->get('username');


/Fredrik
This topic is locked and no more replies can be posted.