PHP curl cannot read a page - php

PHP curl at our localhost works fine but not on any other server
Here is the code
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:13.0) Gecko/20100101 Firefox/13.0.1" );
curl_setopt($ch, CURLOPT_URL, 'http://50.7.243.50:8054/played.html');
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER ,0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_TIMEOUT,120);
curl_setopt($ch,CURLOPT_MAXREDIRS,20);
$data = curl_exec ($ch);
if ($data == false)
echo "CURL ERROR : ".curl_error($ch)."<br>";
curl_close ($ch);
even if we do this
curl_setopt($ch, CURLOPT_URL, 'http://50.7.243.50/played.html');
curl_setopt($ch, CURLOPT_PORT, 8054);
it shows error couldn't connect to host
Any help is appreciated....

try this code, i have tested and working.
$html = "http://50.7.243.50:8054/played.html";
$header = array();
$header[] = 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$header[] = 'Cache-Control: max-age=0';
$header[] = 'Connection: keep-alive';
$header[] = 'Keep-Alive: 300';
$header[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7';
$header[] = 'Accept-Language: en-us,en;q=0.5';
$header[] = 'Pragma: ';
$ch = curl_init();
$proxy_ip = '122.72.112.148';
$proxy_port = 80;
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_URL, $html);
curl_setopt ($ch, CURLOPT_PORT , 8054);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close ($ch);
echo $result;

Try below code :
$html = "http://50.7.243.50:8054/played.html";
$header = array();
$header[] = 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$header[] = 'Cache-Control: max-age=0';
$header[] = 'Connection: keep-alive';
$header[] = 'Keep-Alive: 300';
$header[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7';
$header[] = 'Accept-Language: en-us,en;q=0.5';
$header[] = 'Pragma: ';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $html);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close ($ch);
echo $result;

Related

cUrl can't access to file but browser does

I want to get file contents (without file_get_contents function) via cUrl but I can't open it with cUrl
My link is here
I tested my hosting with requestb.in and results are here
$header = array();
$header[] = 'Accept-Encoding: gzip';
$header[] = 'Connection: close';
$header[] = 'Host: panel.1n3k.com';
$header[] = 'User-Agent: runscope-radar/2.0';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
curl_close($ch);
I tried with agent CURLOPT_USERAGENT with my browser's agent.
CURLOPT_REFERER, CURLOPT_ENCODING, CURLOPT_AUTOREFERER
one by one but no one could help me...
How this can be posible ?
try this one to view your link image contents
<?php
header("Content-Type: image/jpeg");
$url = 'http://panel.1n3k.com/6512bd43d9caa6e02c990b0a82652dca/api/media/4/logo/831710_1464331440.png';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11');
$res = curl_exec($ch);
$rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch) ;
echo $res;
?>

PHP cURL - how to emulate exactly same request like user?

I am trying to make a website scraper, but the website is acting diferrently, than normal request via browser.
How can i make perfect cURL reguest, that the website will not filter it and block it?
Any help would be appriciated.
$curl_handle = curl_init ("***");
$header = array();
$header[] = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0";
$header[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$header[] = "Accept-Language: cs,en-US;q=0.7,en;q=0.3";
$header[] = "Accept-Encoding: utf-8";
$header[] = "Connection: keep-alive";
$header[] = "Host: ****";
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0');
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $header);
curl_setopt ($curl_handle, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookie.txt');
curl_setopt ($curl_handle, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($curl_handle, CURLOPT_AUTOREFERER, true);
$output = curl_exec ($curl_handle);
This is, what i got so far, but it is still getting blocked.
The following CURL options might help:
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

videoslasher video download script php

I got a problem with downloading video from videoslasher.com. I wrote a script to get source link and it is working fine.
Example link:
http://storage2.videoslasher.com/free/K/K1/K1Z6TBW88QCM.flv?h=XeahiwUFe_yHiduYx5EzBg&e=1377200810
But when i am downloading with script i get 403 (forbidden).
Code downloading video:
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$headers[] = 'Accept-Language: pl,en-us;q=0.7,en;q=0.3';
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Connection: keep-alive';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.videoslasher.com/static/player/flowplayer.commercial-3.2.7.swf');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE,'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_BUFFERSIZE, 4096000);
echo curl_exec($ch);
curl_close($ch);
Does anyone know what could be the problem?

Why cURL gives different output on server and localhost?

The below code gives different output on localhost and server.
I tried changing useragents and browsers. Am I missing any header?
<?php
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$headers[] = 'Accept-Language: en-us,en;q=0.5';
$headers[] = 'Accept-Encoding gzip,deflate';
$headers[] = 'Keep-Alive: 300';
$headers[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7';
//$headers[] = 'Content-Length: 0';
$curl = curl_init();
curl_setopt($curl, CURLOPT_HEADERFUNCTION, 'dbg_curl_data');
curl_setopt($curl, CURLOPT_WRITEFUNCTION, 'dbg_curl_data');
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7');
//curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11');
curl_setopt($curl, CURLOPT_URL, "http://www.facebook.com/login.php");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
//curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
//curl_setopt($curl, CURLOPT_POST, true);
$html = curl_exec ($curl);
//curl_close ($curl);
echo '<fieldset><legend>request headers</legend>
<pre>', htmlspecialchars(curl_getinfo($curl, CURLINFO_HEADER_OUT)), '</pre>
</fieldset>';
echo '<fieldset><legend>response</legend>
<pre>', htmlspecialchars(dbg_curl_data(null)), '</pre>
</fieldset>';
echo '<fieldset><legend>$html</legend>
<pre>', htmlspecialchars($html), '</pre>
</fieldset>';
function dbg_curl_data($curl, $data=null) {
static $buffer = '';
if ( is_null($curl) ) {
$r = $buffer;
$buffer = '';
return $r;
}
else {
$buffer .= $data;
return strlen($data);
}
}
?>
Output on Localhost : http://pastebin.com/UbpTVc4f
Output on Server : http://pastebin.com/NURDksJy
I want output as its on localhost.
Why don't you start with something simple before you complicate your request as much as it is now and is hard to debug. For example, this code (run it in a separate file):
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7');
curl_setopt($curl, CURLOPT_URL, "http://www.facebook.com/login.php");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
$html = curl_exec ($curl);
print_r($html);
Should give you HTTP/1.1 302 Found in return.

Login to AOL mail with curl PHP

I make a reseach for a long time but the result is not good, it's always return me to the login page. I've set the post params, header, proxy ....
I use the Live HTTP Headers plugin of FireFox to se what is the POST content contains and then set it to my code, but it still not work. Here is my code:
function show($content)
{
echo "<textarea>$content</textarea>";
}
function aol($mail,$pass, $_sock){
$url="http://mail.aol.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt($ch, CURLOPT_PROXY, $_sock);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$content=curl_exec ($ch);
$this->show($content);
//Get SNS_SC
$SNS_SC=explode('SNS_SC=', $content);
$SNS_SC=explode(';', $SNS_SC[1]);
$SNS_SC=$SNS_SC[0];
// //Get Site State
$siteState=explode('siteState" value="', $content);
$siteState=explode('"', $siteState[1]);
$siteState=$siteState[0];
//Get usrd
$usrd=explode('usrd" value="', $content);
$usrd=explode('"', $usrd[1]);
$usrd=$usrd[0];
$url="https://my.screenname.aol.com/_cqr/login/login.psp";
$post="sitedomain=sns.webmail.aol.com&siteId=&lang=en&locale=us&authLev=0&siteState=$siteState&isSiteStateEncoded=true&mcState=initialized&uitype=std&use_aam=0&offerId=newmail-en-us-v2&seamless=novl&regPromoCode=&usrd=$usrd&doSSL=&redirType=&xchk=false&tab=&lsoDP=&loginId=$mail&password=$pass";
//ref
$ref="https://my.screenname.aol.com/_cqr/login/login.psp?sitedomain=sns.webmail.aol.com&lang=en&seamless=novl&offerId=newmail-en-us-v2&authLev=0&siteState=$siteState&locale=us";
//
$arr[] = "Host: my.screenname.aol.com";
$arr[] = "User-Agent: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1";
$arr[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$arr[] = "Accept-Language: en-us,en;q=0.5";
$arr[]="Accept-Encoding: gzip, deflate";
$arr[]="Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$arr[] = "Keep-Alive: 300";
$arr[] = "Connection: keep-alive";
$arr[] = "Referer: ".$ref;
$arr[] = "Cookie: SNS_SC=" . $SNS_SC ;
$arr[] = "Content-Type: application/x-www-form-urlencoded";
$arr[] = "Content-Length: " . strlen($post);
//$arr[] = $post;
//
curl_setopt($ch, CURLOPT_HEADER, $arr);
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $ref);
$result=curl_exec ($ch);
curl_close ($ch);
//$this->show($result);
echo $result;
return 0;
}
Any idea? Thanks :)

Categories