2014-01-15 48 views
0

我想登錄www.z8games.com並轉到設置頁面,這是我使用的代碼,錯誤如下。cURL登錄和重定向[這是一個ASP.net頁面]

<?php 
    $url = 'http://www.z8games.com/loging/globelogin.aspx?b=4&from='; 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    $html = file_get_contents($url); 
    preg_match('~<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\"(.*?)\" />~',$html,$viewstate); 
    preg_match('~<input type=\"hidden\" name=\"__EVENTVALIDATION\" id=\"__EVENTVALIDATION\" value=\"(.*?)\" />~',$html,$eventvalidation); 
    $vstate = $viewstate[1]; 
    $eval = $eventvalidation[1]; 
    $post_fields='__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=' . urlencode($vstate) . '&__EVENTVALIDATION=' . urlencode($eval) . '&tb_loginid=Heroboss123&tb_password=Droppers1&ib_login.x=11&ib_login.y=19'; 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); 
    curl_setopt($ch, CURLOPT_ENCODING, ""); 
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7s"); 
    curl_setopt($ch, CURLOPT_REFERER, $url); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, '/cookie.txt'); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, '/cookie.txt'); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // Changing from page 
    curl_setopt($ch, CURLOPT_URL, "http://www.z8games.com/myaccount/myaccount.aspx"); 
    $store = curl_exec($ch); 
    echo $store; 

    curl_close($ch); 
?> 

它返回:

error page

+0

那麼,您是否嘗試啓用「調試模式」建議?你甚至可以訪問aspx頁面嗎? 'z8games'甚至是你的網站? –

+2

它違反了z8games使用條款,所以也許你不應該這樣做。 – 2014-01-15 19:06:03

+0

我沒有看到任何關於登錄到他們的網站。 – Joery

回答

0

您張貼登錄憑證到錯誤的URL。

刪除此:

curl_setopt($ch, CURLOPT_URL, "http://www.z8games.com/myaccount/myaccount.aspx"); 

,並使用此:

curl_setopt($ch, CURLOPT_URL, $url); 

UPDATE:

獲得來自另一頁的內容,更改URL,並使用HTTP請求作爲GET。目前你正在做它POST。所以它應該是:

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 
curl_setopt($ch, CURLOPT_URL, "http://www.z8games.com/myaccount/myaccount.aspx"); 
+0

我想登錄並更改頁面,登錄確實有效,但是從頁面更改不起作用。 – Joery

+0

我已經更新了答案。 –

+0

好吧,但它只是繼續加載,並在最後返回一個白頁。 – Joery