1
我試圖做一個捲曲,登錄在一個網站,問題是,我不斷收到錯誤500 - 內部服務器錯誤。錯誤500與PHP捲曲
代碼:
<?php
$path = $_SERVER["DOCUMENT_ROOT"]."/teste/ctemp";
//login form action url
$url="https://example/security_check";
$postinfo = "username=xxx&password=xxxx";
$website="https://example/account";
$base="https://example/";
$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 optional
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0");
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, 1);
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 grab
curl_setopt($ch, CURLOPT_URL, $website);
//do stuff with the info with DomDocument() etc
$html = curl_exec($ch);
curl_close($ch);
$html = preg_replace("/<head>/i", "<head><base href='$base' />", $html, 1);
echo $html;
該網站是https://example/中,auth形式submited到https://example/security_check與崗位的用戶名和密碼,一個SUCESSFUL登錄後,頁面會被重定向到例如/佔到
有什麼問題用我的代碼?
請在每一行中設置一個'var_dump('try 1').... var_dump('try n')',你會看到它的中斷點。這是一種更快的做法。我希望能幫助你。 –
該代碼在我試過的另一個網站上運行得非常好,問題僅在於我嘗試捲曲的這個問題,我做了一些調查,看起來是因爲存儲在登錄頁面中的Cookie,我打電話給auth形式直接通過郵件,任何提示爲此? –
如果您應該向我發送完整的代碼或發送給我鏈接,我需要對其進行測試。 –