I\'m creating a bilingual site and have decided to use session_start
to determine the language of the page using the following:
session_start();
Based on this answer and the answers given here, it's best to use the following code snippets:
For versions of PHP >= 5.4.0, PHP 7:
function register_my_session() {
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
}
add_action('init', 'register_my_session');
Reference: http://www.php.net/manual/en/function.session-status.php
For versions of PHP < 5.4.0:
function register_my_session() {
if(session_id() == '') {
session_start();
}
}
add_action('init', 'register_my_session');
Reference: https://www.php.net/manual/en/function.session-id.php
I don't want to take any credits, I just felt like sharing this information would be helpful.