I've trying to build Joomla into my existing website so I can use it for premium content.
I've already got a custom-built authentication system that sets my own session variables.
For some reason, Joomla (which is located in a different directory) doesn't want to recognize these session variables, even when adding the session_start(); line at the top of all Joomla pages.
Any idea how I can get Joomla to recognize my custom session variables so I can limit the content located in Joomla to only premium users?
Thank you.
Joomla 1.5 uses a JSession class.
As everything in Joomla is powered by it's own internal framework, I wouldn't recommend writing pure PHP for something like sessions, as it's likely that Joomla overwrites old session variables when it initializes it's own internal session management code.
I used
jumi
, a great free component forjoomla
which links to any file and maintains session data.If you need a clean page, use
ob_end_clean();
at the top of the new file anddie;
at the end to clear the joomla template.Joomla will most likely initialize it's own session (we'll call it session "B") separate from the other system you're talking about which determines if the user gets the "premium" session (we'll call this session "A"). Once session "B" starts, I don't think it will be possible for session "B" to access information in session "A".
My suggestion for getting around this would be to write the session handling code in pure PHP and run that code before Joomla loads it's own session. That way when you run session_start() it should catch session "A".
A good way to get this into Joomla would be to write a "System" plugin and call the function "onAfterInitialise" this function get's called before Joomla has even setup it's session (at least, I'm pretty sure about that.. haha).
Maybe your authentication system uses cookies and sets a cookie path that prevents then browser from sending the session-id cookie back to the joomla script.
The cookie path would probably be set via session_set_cookie_params() or ini_set().
Joomla uses their own session management so when you use php session it wont work guarantee. To get around this just try to juse joomla session management.
This may solve you problem.
I know this is an old question, but I decided to post a solution here in case someone is still looking for it.
Joomla does use its own framework and session management. You can still write your own php files and access Joomla session variables. You just need to load the joomla framework into your php script.
For J1.6 you need to include the following lines at the beginning of your php script. NOTE: these need to be included at the very top as joomla is going to call a session_start().
Once you do that you can store session variables using:
read session variables using:
and unset session variables using:
This works for J1.6. You will probably need to change the lines that load the joomla framework for other versions. I would start with the index.php in the Joomla's root directory as it has to load the framework.
I hope this helps.