如何使用cUrl从其他网站获取Cookie?
我想获取此https://ais.usvisa-info.com/en-ae/niv/users/sign_in网站的Cookie!
例如:
Cookie:
_ga=GA1.2.1101352908.1469077182; _yatri_session=TTNTOWhoQjJoTHVNNkVnQ29XOGxqVUZxQzJXYWpBZjhOQWhaSFVnQlhqUDhSLytCelA2K2UvSEl1TG1MUmRDL2JUNi95b1pRa2pJVGpGdmxGWmh6dWI0ckppOVVoUnNObWJjLyt0MFF2bmppeGJLNEVxNFdaODBQQWhPb3VrSlh3bTJoWGVpTFdwSTJxRFpPNVRSeTBlZHg3bWR1WnVKZk0rMWRCeHYxSnFESG5EVVJlRnRJbytGZUl4SzAzYjdkWnoySFcySkt1MW53UlpJU21mcGpROHppVHdJblJmWDB4clFTTHRtR1BtM29lVUtqMWtBaERLeVp5d094SFBhYldyR1NvTHR5dFBGMDdCYVlhcWdiM0ttSzFCRWxpNHZMaktKMEpGd01Ub0p3enpVZFVLSDBrb2VhdmNTWDJOazJ0MkFCemVpci85aWZKS1JPczhiaml2eEQ1YTYzZVUzcDJ5K2dRYUk2dnAxUnNTTk5yMkpaY2VOVWJCRUM5bERlLS1ITFFaK05wNWFmaDhUOTZlYVhlbk5RPT0%3D--dc9cf7a71467b9d93e656e087ccf4a3841304cb5
答案 0 :(得分:1)
检查以下代码:
<?php
// open a site with cookies
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://ais.usvisa-info.com/en-ae/niv/users/sign_in");
curl_setopt($ch, CURLOPT_HEADER ,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$content = curl_exec($ch);
// get cookies
$cookies = array();
preg_match_all('/Set-Cookie:(?<cookie>\s{0,}.*)$/im', $content, $cookies);
echo $cookies['cookie'][0];
?>