用 curl 登录 然后 下载文件
在工作中遇到需要登录一个网站然后从这个网站下载一些东西问题,经过一天的编写,查找和测试,做出以下代码用于实现. $dir = « /home/tools/ctemp »; $cookie_file_path = $dir. »/cookie.tmp »; function get_connexion($cookie_file_path) { $username = « xxxxx »; $password = « xxxxx »; $url = ‘https://xxxxxxxxx/xxxxxx/xxxxx’; $postinfo = « login= ».$username. »&password= ».$password; $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_NOBODY, false); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // 这个如果不设置,默认是检测ssl链接的,会报错 curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); //set the cookie the site has for certain features, this is […]