Recent Topics

Save visitors locale in Session data

Started by on Mar 20, 2013 – Contents updated: Mar 20, 2013

Mar 20, 2013 19:28    

This will allow us to create manual locale selectors.

- a website visitor opens a link with ?locale=en-US URL param, and this locale is saved into the Session
- now all other pages opened in this session are displayed in en-US locale

Also allow ?locale=reset to switch back to default blog/site locale

Mar 20, 2013 19:55

Here's a simple example, it needs to be extended with locale check to make sure we don't save invalid locales.


// Detect visitor's locale
if( ! $Session->has_User() )
    if( $locale param('locale''string') )
        if( $locale == 'reset' )
        {    // Reset saved locale
        {    // Save selected visitor's locale for this session
    // Activate saved locale
    locale_activate$Session->get('manual_locale') );

Form is loading...

Open-Source CMS – This forum is powered by b2evolution CMS, a complete engine for your website.