简体   繁体   中英

PHP session_start() not working if not login wordpress

If I have log in wp admin then my session is working but if I have no login in WP-admin then session is not working. How can I solve that?

<?php 
session_start();

global $post;
if( $post->ID == 22 ) : 
    session_unset(); 
    echo "Login Page";
else : 
endif;

Try this:

remove session_start from your code.

add this code in your functions.php:

add_action ('wp_loaded', 'myInitSession' );

function initSession(){ 
    if( !session_id() ){
        session_start();
    }
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM