Answer the question
In order to leave comments, you need to log in
How to get data from session without session_start()?
It is necessary to get previously saved data from the session, but without initializing session_start();
The problem is that after saving the data to the session, you need to run several copies of the script using curl_multi_init, but with different parameters.
Alas, you cannot use session_start() to get data, because php does not support multi-threaded work with sessions. Even for casual reading...
Answer the question
In order to leave comments, you need to log in
I made a little hack - I pass all the data from the session in encoded form, in a POST request.
At the output, I get all the data from it :)
And I return all the data written to the $_SESSION variable in json form, and when I receive it, I write it where necessary.
Sessions are stored in files, you can open them as a file and parse using session_decode , but you will still need to do session_start before session_decode, resetting the session before that, for example.
PS In general, this is nonsense, use a database to store data.
Is there a function that might help?
/**
* Wraps around $_SESSION
*
* @param string $name name of session variable to set
* @param mixed $value value for the variable. Set this to null to unset the variable from the session.
*
* @return mixed value for the session variable
*/
function session($name, $value = null) {
static $session_active = false;
if ($session_active === false) {
if (($current = ini_get('session.use_trans_sid')) === false)
exit('Calls to session() requires [session.use_trans_sid] to be set');
$test = "mix{$current}{$current}";
$prev = @ini_set('session.use_trans_sid', $test);
$peek = @ini_set('session.use_trans_sid', $current);
if ($peek !== $current && $peek !== false)
session_start();
$session_active = true;
}
if (func_num_args() === 1)
return (isset($_SESSION[$name]) ? $_SESSION[$name] : null);
if ($value === null)
unset($_SESSION[$name]);
else
$_SESSION[$name] = $value;
}
1. To store the session, you can use not only files, but also storage that supports multithreading (memcached, redis, relational databases, ....).
2. Even if you use files, what prevents you from calling session_write_close before running curl?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question