2014-01-15 47 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