[英]How can I receive captcha image (using PHP cURL)
From the code you see below, even though I tried for a long time, I do not get any data.从您在下面看到的代码中,即使我尝试了很长时间,也没有得到任何数据。 Unfortunately, when I view the browser a captcha comes the first time.不幸的是,当我查看浏览器时,第一次出现验证码。 I tried refreshing the page but I get a blank page.我尝试刷新页面,但我得到一个空白页面。
In addition, there is another page called security2.php and when I refresh this page, I constantly get a new captcha.此外,还有一个名为 security2.php 的页面,当我刷新此页面时,我不断得到一个新的验证码。
Also strange, security and security2.php and 3.php I'm getting a blank page.同样奇怪的是,security 和 security2.php 和 3.php 我得到了一个空白页面。
My Code:我的代码:
<?php
define('COOKIE', './cookie.txt');
header('Content-Type: image/png');
$x=rand(0,1000);
$url="http://www.turktuccar.com/security2.php?id=$x";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
$cookie = realpath('cookie.txt');
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE);
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
$http_headers = array(
'Host: www.turktuccar.com',
'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding: gzip, deflate',
'DNT: 1',
'Connection: keep-alive',
'Cache-Control: max-age=0'
);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.turktuccar.com/numara-sorgula/');
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
curl_exec($ch);
curl_close($ch);
?>
You've to echo curl_exec($ch);
你必须回curl_exec($ch);
, try this instead: ,试试这个:
<?php
header('Content-Type: image/png');
$x=rand(0,1000);
$url="http://www.xxxxxx.com/security2.php?id=$x";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
echo curl_exec($ch);
curl_close($ch);
?>
UPDATE:更新:
Based on your comments, you don't have curl installed on php.根据您的评论,您没有在 php 上安装 curl。 You can use file_get_contents()
instead, ie:您可以使用file_get_contents()
代替,即:
<?php
header('Content-Type: image/png');
$x=rand(0,1000);
$url= file_get_contents("http://www.xxxxxx.com/security2.php?id=$x");
echo $url;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.