Forums » SEPHP Help and Tips

Turning off the en4_locale and en4_language cookies

    • 171 posts
    June 11, 2020 2:56 AM EDT

    Another admin in another thread asked how to turn off the en4_locale and en4_language cookies as they were not used on their site. These cookies store the language and locale that is selected for site users who are not logged in. 

     

    The Social Engine code essentially does three things with each page request with regards to language and locale:

    1. For users that are logged in, checks the database and uses the language and locale values that the site user has set there;
    2. If the user is not logged in AND has visited the site before, user the language and locale values found in the cookies;
    3. If the user is not logged in and has no cookies showing the language and locale available, uses the default value that was set by the site admin in the admin panel.

     

    One caveat might be that a Third Party Module might use the cookies instead of the database or the site setting given that they are always available.

     

    Therefore, if your site only has one language and locale available, you also do not need these cookies. One major advantage of turning these cookies off is that the only cookie that is used in Social Engine is that set by PHP for session management, by default called phpsessid.

     

    At least in the UK, although likely elsewhere in the EU as the law should be similar in all of them, you are NOT required to warn users about your use of cookies or gain their consent for them, as that cookie would be covered by both the "strictly necessary" (as it is necessary for the site to function) and the "communication" exemption (as it is how PHP identifies the client endpoint). This reduces the compliance burden and user burden of ticking boxes to acknowledge (and if necessary, consent to) the use of cookies.

     

    If you want to turn off these cookies, you will need to make a source code modification. SOCIAL ENGINE DO NOT SUPPORT SOURCE CODE MODIFICATIONS AND YOU WILL NEED TO CHECK THE SOURCE MODIFICATION EACH TIME YOU UPGRADE YOUR SITE AND IF NECESSARY, REAPPLY IT.

     

    There are two files that you need to modify.

     

    The first can be found at /application/modules/Core/Bootstrap.php and there are two parts of the code you need to comment out, at lines 981 to 985:

     

    } /* elseif (!empty($_COOKIE['en4_language']) && !empty($_COOKIE['en4_locale'])) { $locale = $_COOKIE['en4_locale']; $language = $_COOKIE['en4_language']; }*/ else {

     

    and at lines 1012 to 1022:

     

    /* if (!$viewer->getIdentity()) { if (empty($_COOKIE['en4_language'])) { setcookie('en4_language', $translate->getLocale(), time() + (86400*365), '/'); } if (empty($_COOKIE['en4_locale'])) { setcookie('en4_locale', $locale, time() + (86400*365), '/'); } } */

    You will also need to edit /application/modules/Core/controllers/UtilityController.php at lines 78 and 79:

     

    //setcookie('en4_language', $language, time() + (86400*365), '/'); //setcookie('en4_locale', $locale, time() + (86400*365), '/');

     

    THESE CODE EDITS ARE AT THE CORRECT LOCATIONS AND TESTED WITH SOCIAL ENGINE 5.1 only. 

     


    This post was edited by abuk at June 11, 2020 3:01 AM EDT
    • Moderator
    • 5214 posts
    June 11, 2020 4:58 AM EDT

    Thank you for mentioning that source code edits will void support with SocialEngine and be overwritten or could break upgrades. Thank you also for posting your tips.


    This post was edited by Donna at June 11, 2020 4:59 AM EDT
    • 14 posts
    June 11, 2020 7:40 AM EDT

    Great post and a very good description .. thank you very much.

    • 73 posts
    July 3, 2020 6:10 AM EDT

    This is a very necessary tip for me.
    Thank you very much.