How to use session_start in Wordpress?

后端 未结 4 1216
悲哀的现实
悲哀的现实 2020-12-09 04:05

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


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 04:25

    I found an interesting article by Peter here. I'm using the following code in my functions.php:

    add_action('init', 'myStartSession', 1);
    add_action('wp_logout', 'myEndSession');
    add_action('wp_login', 'myEndSession');
    
    function myStartSession() {
        if(!session_id()) {
            session_start();
        }
    }
    
    function myEndSession() {
        session_destroy ();
    }
    

    This destroys old session when user logs out then in again with different account.

提交回复
热议问题