在php中发送第二个请求时如何保留会话?

在php中发送第二个请求时如何保留会话?,php,node.js,session,curl,session-cookies,Php,Node.js,Session,Curl,Session Cookies,我的问题是,当我第一次登录到node.js应用程序时,将数据从PHP同步到node js。但在登录后,当我在第二个请求中发送数据时,会话没有使用curl请求发送数据,因此它显示“未登录” 这是我的日志代码: $data_string = json_encode(['userid' => $user_name, 'password' => $password]); $URL = $url; $ch = curl_init('http://192.168.1.16:8000/

我的问题是,当我第一次登录到node.js应用程序时,将数据从PHP同步到node js。但在登录后,当我在第二个请求中发送数据时,会话没有使用curl请求发送数据,因此它显示“未登录”

这是我的日志代码:

$data_string = json_encode(['userid' => $user_name, 'password' => $password]);
$URL = $url;     

$ch = curl_init('http://192.168.1.16:8000/auth/login');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string))                                                                 
);

$result = curl_exec($ch);
它正在发送数据旋度代码:

$data_string = json_encode(['import_export' =>$json]);                                                                                   

https://stackoverflow.com/users
    $ch = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL => 'http://192.168.1.16:8000/api/all',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $data_string,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTPHEADER => array(                                                                          
            'Content-Type: application/json',                                                                                
            'Content-Length: ' . strlen($data_string)
        )
    ));

    $result = curl_exec($ch);

告诉cURL使用Cookie:

curl_setopt(CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
curl_setopt(CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
这样,基于默认节点/Express会话cookie的身份验证应该可以工作,因为会话cookie将在登录时保存,并与后续请求一起发送


这是基于cookie的登录吗?然后阅读如何使cURL正确处理这些。我使用node session在nodejs API中存储登录信息。nodejs不处理会话cookie,Express处理。是的,我使用Express创建服务器。