A
A
Andrzej Wielski2013-12-16 06:02:08
PHP
Andrzej Wielski, 2013-12-16 06:02:08

How to resume the session in another script, which I access via curl?

Hello.
It is necessary to somehow resume the session in another script, which I access via curl.
There are two scripts on the server - 1.php and 2.php
In 1.php the following code:

session_start();
$_SESSION[0] = '123';
$url = 'http://сайт/2.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
          
$html = curl_exec($ch);
echo $html;

In 2.php the following code:
session_start();
print_r($_SESSION);

Alas, this option does not work, the script simply crashes with a Fatal Error.
Fatal error: Maximum execution time of 30 seconds exceeded in ... on line 21

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrzej Wielski, 2013-12-16
@wielski

Solution: You need to close the entry to the session before getting data from it in another script.
session_write_close();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question