2012-04-26 25 views
0

我需要登錄,收集任何cookie,並繼續下一頁進行身份驗證。如何使用cURL登錄此頁面? PHP

<form action="logon.asp" method="post" name="FmDefault" id="CkIn">  
<table width="90%" border="0" cellpadding="0" cellspacing="0"> 
<tr>  
    <td colspan="2"> 
     <div align="right"><img src="images/some_image.gif" width="85" height="20"> 

     <input name="u_id" type="text" size="15" maxlength="10"> 

     </div> 
    </td> 
</tr> 
<tr> 
    <td colspan="2"> 
     <div align="right"><img src="images/some_other_image.gif" width="85" height="20"> 

     <input name="ps_word" type=password size="15" maxlength="10"> 

     </div> 
    </td> 
</tr> 
<tr> 
    <td colspan="2"> 
     <div align="right"> 

     <input alt="Login" type="image" src="images/button_image.gif" width="57" height="25" border="0"> 
     </div> 
    </td> 
</tr> 
<tr> 
<td><font color='#ff0000'> 

<!---  
<b>ATTENTION: <br>  
</b></font><b><span class="style1"><a href="http://www.example.com/holiday2009.asp" target="_blank" style="color:#00FF00;">CLICK HERE FOR THE <br>  
EXAMPLE 2008 HOLIDAY SCHEDULE!</a></span></b>  
-->  
</td>  
</tr> 
</table> 
</form> 

回答

1
$ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, 'http://example.com/logon.asp'); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'u_id=YOUR_USERNAME&ps_word=YOUR_PASSWORD'); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
    $store = curl_exec($ch);