简体   繁体   中英

Sending a request with curl and a cookie loaded by the browser

I have got this code:

    public function get_thead_page($cookie=null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
            curl_setopt($ch, CURLOPT_COOKIEFILE,'');
              if($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie);
$data = curl_exec($ch);
curl_close($ch);
return $data;
 }

Now I dont want to use my cookie value, but I want the browser to handle it for me. I wan tthe request to behave as if it was given by the browser.

So I want to the cookie to be loaded with the request instead of providing a value...

There is that value..

curl_setopt($ch, CURLOPT_COOKIEFILE,'');

which asks for the cookie file location...but I dont want to specify the location, I want the request to be sent with a cookie being loaded somehow without specifying the path on the system..

Is there any solution?

The browser can't do that. CURLOPT_COOKIEFILE refers to a server-side file which the browser have no access. You're the one who made this app. It's to you to choose the cookie's location when you create it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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