How to get rid of the session expire in Joomla. Joomla has added a function since 1.5 version to keep session alive while editing or creating articles,messages,managing media,etc.
The function lacated in libraries/joomla/html/html/behavior.php
If you want use the function to make your extension "keep alive",simply add
JHtml::_('behavior.keepalive');
at the beginning of the page.
See the code of the function of keepalive bellow:
/** * Keep session alive, for example, while editing or creating an article. * * @return void * @since 1.5 */ public static function keepalive() { static $loaded = false; // only load once if ($loaded) { return; } // Include mootools framework self::framework(); $config = JFactory::getConfig(); $lifetime = ($config->get('lifetime') * 60000); $refreshTime = ($lifetime <= 60000) ? 30000 : $lifetime - 60000; //refresh time is 1 minute less than the liftime assined in the configuration.php file // the longest refresh period is one hour to prevent integer overflow. if ($refreshTime > 3600000 || $refreshTime <= 0) { $refreshTime = 3600000; } $document = JFactory::getDocument(); $script = ''; $script .= 'function keepAlive() {'; $script .= ' var myAjax = new Request({method: "get", url: "index.php"}).send();'; $script .= '}'; $script .= ' window.addEvent("domready", function()'; $script .= '{ keepAlive.periodical('.$refreshTime.'); }'; $script .= ');'; $document->addScriptDeclaration($script); $loaded = true; return; }
Kee Huang
Email: This email address is being protected from spambots. You need JavaScript enabled to view it.