Session Variable does not work WordPress [duplicate]

1

I can not retrieve the session variable using the following code

This is a file where requests are sent, I declare a session variable to use on another page that is called after the file is finished.

<?php
    $parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
    require_once( $parse_uri[0] . 'wp-load.php' );
    $_SESSION["enviou"] = "true";
?>

On this other page, I try to recover as simply as possible

if ($_SESSION["enviou"] == "" || $_SESSION["enviou"] == null){
     header("location:http://www.google.com.br");   
}else{
    $_SESSION["enviou"] == null;
}

But the variable is always empty, even if it is declared in the previous file.

When I enter the code session_start(); I get the following errors:

Warning: session_start() [function.session-start]: open(/var/lib/php-cgi/session/sess_6aqo4l2r50v2hguu8pnrqusvr7, O_RDWR) failed: No such file or directory (2) in /home/storage/a/6a/25/..../public_html/vl/wp-content/themes/....../page-formbarraresposta.php on line 2
Warning: Unknown: open(/var/lib/php-cgi/session/sess_6aqo4l2r50v2hguu8pnrqusvr7, O_RDWR) failed: No such file or directory (2) in Unknown on line 0'
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php-cgi/session) in Unknown on line 0

Can this be a server error? Since this same code has already been used in another project and has worked perfectly.

    
asked by anonymous 07.05.2017 / 05:34

1 answer

0

The error is quite explicit in that it says, the path where PHP saves the sessions did not exist on my server, so I found the code

session_save_path(realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../tmp'));
session_start();

And then it worked perfectly.

    
10.05.2017 / 12:28