2013-07-04 84 views
-1

我需要使用CURL來顯示來自url的圖像。但運行此代碼後,我只能獲取文本數據。沒有圖像顯示?在$一個含有驗證碼圖像,我希望用戶通過看image.plz幫助填寫驗證碼...從curl結果中提取圖像

curl_setopt($ch, CURLOPT_USERAGENT,$usergaent); 
curl_setopt($ch, CURLOPT_URL, 'http://sitproject.com/verification.asp?source=login'); 
curl_setopt ($ch, CURLOPT_HTTPHEADER, $httpheader); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 
curl_setopt($ch,CURLOPT_REFERER,"http://site2sms.com/login.asp"); 
$one = curl_exec($ch); 
echo $one; 


while debugging $one contains this only no binary image data: 

<body> 
<div class="success">Thanks for using Sitproject.Com! You are logged into your Account Successfully to Proceed Further Please Enter Below Displayed 3 Digits Security Code in the Input Box!</div> 
<table width="1079" height="54" border="0"> 
<tr> 
<td> 
<img src="security/captcha.asp" /> 
<br /> 
Please Type the 3 Digits Displayed above in the Image and Click on Proceed Further Button to use the Free Services? 
<br /> 
<form name="frmVerify" action="auth.asp" method="post"> 
<input type="hidden" name="txtSource" value="captcha" /> 
<input type="text" name="txtCaptcha" maxlength="3" /> 
<input type="submit" value="Proceed Further" /> 
</form> 
</td> 
</tr> 
<tr> 
<td>Note: If you are having any problem with Security Code you can mail us at [email protected]!</td> 
</tr> 
</table> 
</body> 
+0

您是否已經在HTML響應中讀取了消息...? – CBroe

回答

1

你需要第二個請求,請求驗證碼圖像,從看着響應,是:

security/captcha.asp 

我會說因爲有驗證碼,他們可能不希望機器人像這樣試圖使用該服務,所以你需要確認你是不是違反任何條款。

0

你的情況

<?php 
$url = "https://api.github.com/users/softvar"; //enter url to extract from 
$send_curl = curl_init($url); 
curl_setopt($send_curl, CURLOPT_URL, $url); 

curl_setopt($send_curl, CURLOPT_HEADER, false); 
curl_setopt($send_curl, CURLOPT_CONNECTTIMEOUT, 2); 
curl_setopt($send_curl, CURLOPT_USERAGENT,'softvar'); // your useragent name 
curl_setopt($send_curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($send_curl, CURLOPT_HTTPHEADER,array('Accept: application/json', "Content-type: application/json")); 
curl_setopt($send_curl, CURLOPT_FAILONERROR, FALSE); 
curl_setopt($send_curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($send_curl, CURLOPT_SSL_VERIFYHOST, FALSE); 
curl_setopt($send_curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
$json_response = curl_exec($send_curl); 
echo $json_response; // response in JSON 
$response = json_decode($json_response, true); 
echo '</br></br>'; 

$img = $response['avatar_url']; // instead of 'avatar_url' enter the element name which contains the image url 

//while debugging $one contains this only no binary image data: 
?> 
<body> 
<div class="success">Thanks for using Sitproject.Com! You are logged into your Account Successfully to Proceed Further Please Enter Below Displayed 3 Digits Security Code in the Input Box!</div> 
<table width="1079" height="54" border="0"> 
<tr> 
<td> 
<img src="<?php echo $img;?>" /> 
<!-- Your captcha will display here--> 
<br /> 
Please Type the 3 Digits Displayed above in the Image and Click on Proceed Further Button to use the Free Services? 
<br /> 
<form name="frmVerify" action="auth.asp" method="post"> 
<input type="hidden" name="txtSource" value="captcha" /> 
<input type="text" name="txtCaptcha" maxlength="3" /> 
<input type="submit" value="Proceed Further" /> 
</form> 
</td> 
</tr> 
<tr> 
<td>Note: If you are having any problem with Security Code you can mail us at [email protected]!</td> 
</tr> 
</table> 
</body> 

這是一個完全工作的例子。嘗試一下。

這就是你如何取東西的方式。作爲迴應,您將根據您的CURLOPT_HTTPHEADER獲取數據。在這裏我使用了JSON

然後提取你想要的image_url並放到任何你想要的位置。

如果這解決了您的問題,請點擊以接受此問題。

+0

header(「Content-Type:image/bmp」); header(「Content-Disposition:inline; filename = captcha.bmp」); echo $ one; –

+0

我必須轉移這段代碼來分離php,否則它將無法正常工作。因爲頁眉被更改爲image/bmp。 –

+0

我沒有得到你。請清楚解釋你的問題。 – softvar