-1

我需要使用 CURL 显示来自 url 的图像。但运行此代码后,我只能获取文本数据。没有显示图像?$one 包含验证码图像,我希望用户通过查看 image.plz 帮助来填充验证码...

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 support@sitproject.com!</td>
</tr>
</table>
</body>
4

2 回答 2

1

您需要第二个请求来请求验证码图像,通过查看响应,该图像位于:

security/captcha.asp

我想说,鉴于有验证码,他们可能不希望像这样的机器人尝试使用该服务,因此您需要验证您没有违反任何条款。

于 2013-07-04T18:32:03.750 回答
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 support@sitproject.com!</td>
</tr>
</table>
</body>

这是一个完全有效的例子。试试看。

这就是你获取东西的方式。作为响应,您将根据 CURLOPT_HTTPHEADER 获取数据。这里我用过JSON

然后提取您想要的 image_url 并将其放在您想要的任何位置。

如果这解决了您的问题,请单击以接受。

于 2013-07-04T19:02:57.187 回答