我已经放弃了好一阵子,但后来又重新讨论了。由于这个问题是定期查看。最终,这就是我最终使用的对我有用的东西。
define("DOC_ROOT","/path/to/html");//username and password of account$username = trim($values["email"]);$password = trim($values["password"]);//set the directory for the cookie using defined document root var$path = DOC_ROOT."/ctemp";//build a unique path with every request to store. the info per user with custom func. I used this function to build unique paths based on member ID, that was for my use case. It can be a regular dir.//$path = build_unique_path($path); // this was for my use case//login form action url$url="https://www.example.com/login/action"; $postinfo = "email=".$username."&password=".$password;$cookie_file_path = $path."/cookie.txt";$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);curl_setopt($ch, CURLOPT_cookieJAR, $cookie_file_path);//set the cookie the site has for certain features, this is optionalcurl_setopt($ch, CURLOPT_cookie, "cookiename=0");curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);curl_exec($ch);//page with the content I want to grabcurl_setopt($ch, CURLOPT_URL, "http://www.example.com/page/");//do stuff with the info with Domdocument() etc$html = curl_exec($ch);curl_close($ch);更新:此代码绝不打算复制和粘贴。 这是为了展示我如何将其用于特定的用例。您应该根据需要使它适应您的代码。例如目录,vars等



