2013-02-09 57 views
0

如果有人可以帮我解决这个问题,那将会很棒。 这是我到目前为止。当我运行这个并回显dom内容时,我仍然遇到登录页面。但我看不出我做错了什么。PHP cURL帖子字段无法正常工作

$target_url = "https://secretsales.com/"; 
    $fields = array('email' => 'abc', 'password' => '123'); 
    $postFields = http_build_query($fields, '', '&'); 

    // make the cURL request to $target_url 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); 
    curl_setopt($ch, CURLOPT_URL, $target_url); 
    curl_setopt($ch, CURLOPT_FAILONERROR, true); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($ch, CURLOPT_AUTOREFERER, true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    $html = curl_exec($ch); 

    // parse the html into a DOMDocument 
    $dom = new DOMDocument(); 
    @$dom -> loadHTML($html); 

    // grab all the on the page 
    $xpath = new DOMXPath($dom); 

    echo $dom->saveHTML(); 
+3

我只能在这里猜测,但我认为该网站需要在登录之前设置一个cookie。还可以有其他安全检查,如xsrf标记。 – scones 2013-02-09 15:10:47

回答

0

补充一点:

curl_setopt ($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/tmp/cookies.txt"); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/tmp/cookies.txt"); 

此存储的cookie的目录specifed所以也许你可能需要创建该目录。

+0

谢谢!你是对的。我也没有通过所有需要的参数。 – 2013-02-11 22:12:39