After using cURL to log into a remote webpage, how can I then access another webpage and return it as a string?

前端 未结 1 1102
無奈伤痛
無奈伤痛 2021-01-07 10:58

Okay, I\'m pretty new to cURL. I\'ve managed to log into a webpage using cURL and sending POST data, but once I\'m logged in, I\'d like it to load various webpages under the

1条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 11:06

    It generally depends on how the remote site handles state management.

    In most cases, this will be via a cookie, so you'll need to instruct curl to keep track of cookies.

    Something like:

    curl_setopt($curl, CURLOPT_COOKIEJAR, '/tmp/cookies');  //where to write cookies received from server
    curl_setopt($curl, CURLOPT_COOKIEFILE, '/tmp/cookies'); //where to read cookies to send in requests.
    

    ought to get you started there.

    EDIT Blatant Copy/Paste Example (from here - found with about 20 seconds of googling "php curl login"). This looks to be about right:

    0 讨论(0)
提交回复
热议问题