-1

why PHP $_session is not working in wordpress my php code is

session_start();
session_register('lang_opt');  
$_SESSION['lang_opt'] = $_POST['lang_opt'];
$mylang = $_SESSION['lang_opt']; 
echo $mylang;
2
  • where are you calling this code?
    – Bainternet
    Apr 7 '12 at 11:45
  • are you testing this on live server?
    – R T
    Aug 7 '15 at 11:55
2

Yes, you must use a small change for use session in WordPress.

if ( ! session_id() ) session_start();

Better you use a custom function

function my_start_session() {

@session_cache_limiter('private, must-revalidate'); //private_no_expire
@session_cache_expire(0);
@session_start();
}

*Please edit, I write from a mobile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.