I have a problem with a session, it works fine on the local server, but it's not visible on the server, the project is in wordpress, do I have to set something special about wordpress? This is my code .. Thank you very much for the answer.


I made a session on this ID (that's my ID that I'm sending to the server) he's in the session

    $user_id = $arr['id'];
$_SESSION['user_id'] = $user_id;    
$_SESSION['user_email'] = $email;
     $_SESSION['user_id'] = $user_id;

In this file, I need to get that ID from the session, but the server does not see it. but on the local server everything works

    public static function save_account_details() {

    $user_id = $_SESSION['user_id'];

    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
    if ( empty( $_POST['action'] ) || 'save_account_details' !== $_POST['action'] || empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'save_account_details' ) ) {

Are you doing this in a plugin or on a template file?

Also, you certainly want to ensure that you're properly setting up sessions. I recommend doing so in functions.php. e.g:

add_action('init', 'track_sessions', 1);
 function track_sessions() { // if session isn't active, set it
  if(!session_id()) {

And using them as you are:

$_SESSION['my_val'] = $val;

Once done, you need to destroy the session:

add_action( 'your_action_here', 'destroy_session', 10, 5 );

 // All done. Destroy session

function destroy_session() {
| improve this answer | |
  • Hi, this is all in my plugins, can I just put something in the configuration file for the session? – srdjan_stojanovic Oct 31 '17 at 7:57
  • What do you mean it is all in your 'plugins'? WP has its own sessions, from your code above, it is not clear whether you're checking for active sessions before session_start(), or whether you're starting the session multiple times in your plugin(s). To troubleshoot, I'd move the above to functions.php . – Tony M Oct 31 '17 at 16:06

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.