Curl cookies expires vs n / a

7

The question is, in network of the browser console says that cookies do not expire, see the image below:

Butwhenyoutake(makearequestofthese)thesecookieswithcurlexpire:

  

ct0=e3197b1390ba24c4ae827fc6740344fa;Expires=Mon,Oct232017  14:21:33UTC;Path=/;Domain=.twitter.com;Secure

Today%w/w%theynolongerwork.HowdoIgetthesecookies?

So:

$obj=newstdClass;$obj->cookies='';$obj->location='';$request=curl_init();curl_setopt_array($request,[CURLOPT_URL=>'https://twitter.com/',CURLOPT_CUSTOMREQUEST=>'GET',CURLOPT_RETURNTRANSFER=>true,CURLOPT_SSL_VERIFYHOST=>false,CURLOPT_SSL_VERIFYPEER=>false,CURLOPT_HEADER=>true,CURLOPT_COOKIEJAR=>getcwd().'/cookies/'.$username.'.txt',CURLOPT_HEADERFUNCTION=>function($curl,$header)use(&$obj){if(stripos($header,'Set-Cookie:')===0){if(preg_match('/^Set-Cookie:\s*([^=]*)=([^;]*)/mi',$header,$matches)){$obj->cookies.=$matches[1].'='.$matches[2].';';$obj->{$matches[1]}=$matches[2];}}var_dump($header);returnstrlen($header);}]);$response=curl_exec($request);

Beingthat:

if(stripos($header,'Set-Cookie:')===0){if(preg_match('/^Set-Cookie:\s*([^=]*)=([^;]*)/mi',$header,$matches)){$obj->cookies.=$matches[1].'='.$matches[2].';';$obj->{$matches[1]}=$matches[2];}}

Haveyoudonetheworksotheydonotexpirecorrectly?

EDITED

InthedocumentationItranslatedandsaysthefollowing:

  

Curlhasabuilt-inintegratedcookieanalysisenginethat  comesintouseifyouwanttoreconnecttoaserverandusecookies  thatwerestoredinapreviousconnection(ormanually  manuallytotricktheserverintobelievingyouhada  previousconnection).Tousepreviouslystoredcookies,you  executecurlas:

    

curl--cookiestored_cookies_in_file link

And here's what I want:

  

If you want to reconnect to a server and use cookies that have been   stored on a previous connection

How do I do this in PHP?

    
asked by anonymous 23.10.2017 / 10:31

1 answer

4

Documentation on the PHP website about CURLOPT_COOKIEFILE :

  

The name of the file containing the cookie data. The cookie file can   be in Netscape format, or just plain HTTP-style headers dumped into a   filet. If the name is an empty string, no cookies are loaded, but   cookie handling is still enabled.

And in that part:

  

If the name is an empty string, no cookies are loaded, but   cookie handling is still enabled.

Function in which the quotation above is referenced:

bool curl_setopt ( resource $ch , int $option , mixed $value )

Then add CURLOPT_COOKIEFILE to the same address as CURLOPT_COOKIEJAR , so cookies are loaded.

Click here for a similar answer to yours. Click here for the curl options php documentation

    
26.10.2017 / 22:47