简体   繁体   English

使用PHP Codeigniter进行CURL:在curl请求上保持会话

[英]CURL with PHP codeigniter: keep session on curl requests

I've a basic web service written in Delphi. 我有一个用Delphi编写的基本Web服务。 This web service is receiving POST requests with JSON via PHP Curl Library from Phil used on Codeigniter. 此Web服务正在通过Codeigniter上使用的Phil通过PHP Curl库接收带有JSON的POST请求。

The server returns the data according to the request. 服务器根据请求返回数据。

On the first request i send my authentication and i get the respective JSON. 在第一个请求中,我发送身份验证并获取相应的JSON。 On the second request the server identifies a different session. 在第二个请求上,服务器标识另一个会话。

You need to set CURLOPT_COOKIEFILE so that cURL saves its cookies into a file. 您需要设置CURLOPT_COOKIEFILE以便cURL将其cookie保存到文件中。 The reason you are losing your session is because cURL is not persisting your session cookie across all of your requests. 您丢失会话的原因是因为cURL不能在所有请求中都保留会话cookie。

So, for Code Igniter it would be something like this: 因此,对于Code Igniter,它将是这样的:

$this->curl->option(CURLOPT_COOKIEFILE,'saved_cookies.txt');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM