Session Variables from front page dumped

15 years 10 months ago #66590 by chasiv
Hi,

I've edited my index.php page to include a line of code
[code:1]$_SESSION = $my->username;[/code:1]
that saves the currently logged in user to a Session variable. If there is no user logged in, then the session variable is null.

It works fine on my test server (Windows XP Pro) at home, but once I've uploaded it to my website (through a host) it does not seem to save any of the $_SESSION variables set on the front page. I've tested it by viewing the source code to see the session_id info and created a test page to view $_SESSION variables. The Session id is saving from the front page, but no variables.

I've set another page up to test $_SESSION variables and they work on the site, but are just being dropped by Joomla.

Any help/ideas to get this to work would be greatly appreciated.

Thanks,
Chas

Please Log in to join the conversation.

15 years 10 months ago #66592 by chasiv
Replied by chasiv on topic Re:Session Variables from front page dumped
Ironically, Session variables changed on other pages on the site DO reflect to the front page. Part of the code displays the session variables to the source code of the front page, so I can see all Session variables that the front page is aware of.

So it is definitely something in the Joomla code that is not allowing the session variables from the front page to be saved.

Please Log in to join the conversation.

15 years 9 months ago #67840 by upmm019
Replied by upmm019 on topic Re:Session Variables from front page dumped
I just posted a similar question as well.

question for you is about your PHP server settings....

Do you have PHP "REGISTER_GLOBALS" ON or OFF ??

I think the preferred setting is OFF and I'm wondering if that contributes to your problems ??

Please Log in to join the conversation.

15 years 9 months ago #67852 by chasiv
Replied by chasiv on topic Re:Session Variables from front page dumped
Register Globals is off.

What my host came up with for a solution was this code:
[code:1]
define("_JEXEC",true);
define("_VALID_MOS",true);
require( '../../Joomla/globals.php' );
require_once( '../../Joomla/configuration.php' );
require_once( '../../Joomla/includes/joomla.php' );

$mainframe = new mosMainFrame( $database, $option, '.' );
$mainframe->initSession();
$my = $mainframe->getUser();

$user = $my->username;[/code:1]

Just add it to your page and the $user will have the current logged in username as its value.

NOTE: I was not able to use this in a function in an include file though. It had to be hard coded to each page I needed the info on --- but it works.

Hope that helps... as it took about 2 weeks of going back & forth with my host to get it resolved.

Please Log in to join the conversation.

15 years 9 months ago #69471 by beat
Thanks for sharing your solution B)

Beat - Community Builder Team Member

Before posting on forums: Read FAQ thoroughly -- Help us spend more time coding by helping others in this forum, many thanks :)
CB links: Our membership - CBSubs - Templates - Hosting - Forge - Send me a Private Message (PM) only for private/confidential info

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.211 seconds

Facebook Twitter LinkedIn