Custom Sessions with Joomla

后端 未结 7 1230
小蘑菇
小蘑菇 2020-12-30 17:45

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

相关标签:
7条回答
  • 2020-12-30 18:21

    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.

    0 讨论(0)
  • 2020-12-30 18:23

    I used jumi, a great free component for joomla 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 and die; at the end to clear the joomla template.

    0 讨论(0)
  • 2020-12-30 18:25

    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.

    0 讨论(0)
  • 2020-12-30 18:31

    i keep seeing people saying that phpsessions won't work in joomla and i wasn't ready to learn the joomla framework for their session management, i had no time for it, so i've done some tests and i found that if you just start the php session in the main page of your template and not on your website index page it will work fine. just put this line of code on the top page of your template page:

    <?php
    // Starting the phpsession
    session_start();    
    ?>
    
    0 讨论(0)
  • 2020-12-30 18:34

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

    define( '_JEXEC', 1 );
    define( 'JPATH_BASE', realpath(dirname(__FILE__).'/..' )); //you will need to update this path to represent your installation. This path works if you store all your custom php scripts in a subdirectory off the main joomla install directory.
    
    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();
    

    Once you do that you can store session variables using:

    $session->set('msgjson',$msgjson);
    

    read session variables using:

    $msgjson = $session->get('msgjson')
    

    and unset session variables using:

    $session->clear('msgjson');
    

    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.

    0 讨论(0)
  • 2020-12-30 18:35

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

    0 讨论(0)
提交回复
热议问题