curl stop working on my server - php

Curl stop working on my server but it is working perfectly on the other server
Here is my script:
<?php
$proxy_ip = '165.139.149.169';
$proxy_port = '3128';
$url = 'https://www.google.com/search?q=skinny+fiber+ingredients&btnG=Search&client=ubuntu&channel=fs&num=100&ie=utf-8&oe=utf-8&gfe_rd=cr&ei=sw9CVbCuPKaA8QfX0ICYBA&gws_rd=cr';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'https://www.google.com');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0');
curl_setopt($ch, CURLOPT_MAXREDIRS, 5); // Good leeway for redirections.
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
$data = curl_exec($ch);
curl_close($ch);
echo "abc";
echo $data;
?>
http://serpbull.com/dev/curl.php (script not working here)
http://imarkdev.com/serp/curl.php (script working here)
Edit:
Not working script takes very long to respond (curl timeout) and prints empty response.

Use curl_error() function to get more information about the failure.
$data = curl_exec($ch);
if ($data === false)
{
echo 'Curl error: ' . curl_error($ch);
} else {
echo 'Response: ' . $data;
}

Related

PHP cURL code 502 from proxy after CONNECT, but it work for other website

I am trying to connect to an HTTP site (eg http://www.http2demo.io/) using a proxy. But i don't know why it work for a website like google (https) but not for a http website
$url = 'https://google.com'; // **If I replace google.com by http://www.http2demo.io/ or any http website it send me a 502 error**
$proxyauth = 'Flexxa:XWIUHY';
$proxy = '45.77.161.17';
$proxyPort = '505';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//proxy suport
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxyPort);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
//https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/27.0.1453.94 Safari/537.36");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
$output = curl_exec($ch);
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo 'Operation completed without any errors';
}
echo $output;
curl_close($ch);
?>
The first one work but not the other

curl hitting the url but data not recieved by server

Can anyone help me? I am tring to hit a website using curl.
My code is as follows:
$data = array(
'utm_source'=>'Google',
'utm_medium'=>'Google',
'utm_campaign'=>'Sales',
'utm_term'=>'united flights tickets'
);
$data = http_build_query($data, '', '&');
$proxies[] = 'user:password#71.6.46.151:443';
$proxies[] = 'user:password#14.102.19.206:61217';
$proxies[] = 'user:password#187.95.230.65:8080';
$url = 'https://www.example.com/index.php?'.$data;
$ch = curl_init();
if (isset($proxy)) { // If the $proxy variable is set, then
curl_setopt($ch, CURLOPT_PROXY, $proxy); // Set CURLOPT_PROXY with proxy in $proxy variable
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'https://www.google.com');
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
curl_setopt($ch, CURLOPT_URL, $url);
$results = curl_exec($ch); // Execute a cURL request
if (curl_error($ch)) {
$error_msg = curl_error($ch);
}
$info = curl_getinfo($ch);
curl_close($ch);
print_r($error_msg);
print_r($info);
print_r($results);
It hits the website and also displayed in the Google Analytics account, but the only problem is that the refferer and source showing "direct" in Google Analytics.
If there is any other way to achive this, please tell me.

PHP Curl post [savefrom.net]

I am trying to get the download link from savefrom.net website, I am using the following code :
<?php
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$url = 'http://en.savefrom.net/savefrom.php';
$ckfile = dirname(__FILE__)."/c.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data['sf_url'] = "http://www.dailymotion.com/video/x34uoat_hero-behind-the-scenes-part-1-making-of-the-trailer_shortfilms";
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_REFERER, 'http://en.savefrom.net/');
$output=#curl_exec($ch);
$info = #curl_getinfo($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($output, 0, $header_size);
$body = substr($output, $header_size);
//echo "<h1>body</h1><br>".$body . "<h1>Header</h1><br><br>" .$header ;
if(curl_errno($ch)){
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
echo "output is:'" . $output . "'";
echo "<br>";
echo "<h2>info is:</h2>";
print_r($info);
?>
so far the code runs but it gives me alert messagbox which says : goto the website for direct download link!!!. Am i doing something wrong in the code. Is there any alternative way to get video download link from website like dailymotion etc. Thanks for your time
regards

curl_exec is not working

I have this piece of code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $page_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT,
'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
$header[] = "Accept: text/html, text/*";
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$html = curl_exec($ch) or die('111');
curl_close($ch);
echo $html;
exit('1');
I have windows with latest version of Xampp installed with curl enabled.
When I run the code it returns 111 without any errors.
I was expecting it to return the page content and 1
Try something like the example from the manual:
if(($html = curl_exec($ch)) === false)
{
echo 'Curl error: ' . curl_error($ch);
die('111');
}
curl_close($ch);
echo $html;
exit('1');
http://php.net/manual/en/function.curl-error.php
Don't die with a fixed error message. Try
$result = curl_exec($ch);
if ($result === FALSE) {
die(curl_error($ch));
}
instead. have curl tell you WHY it failed, instead of just spitting out some pointless 111 text.

curl error: couldn't connect to host

I am trying to use curl with a proxy. I have the following code:
function getPage($proxy, $url, $referer, $agent, $header, $timeout) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$result['EXE'] = curl_exec($ch);
$result['INF'] = curl_getinfo($ch);
$result['ERR'] = curl_error($ch);
curl_close($ch);
return $result;
}
$result = getPage(
'75.125.147.82:3128', // use valid proxy
'http://www.google.com/',
'http://www.google.com/',
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8',
1,
5);
if (empty($result['ERR'])) {
echo $results['EXE'];
} else {
echo $result['ERR'];
}
The output of this script is 'couldn't connect to host'
Anyone know whats wrong?
You might check what the status code is of where you're connecting to:
$status = curl_getinfo($http, CURLINFO_HTTP_CODE);
Might give you an idea of what is going on.
well
delete this code
curl_setopt($ch,CURLOPT_HTTPPROXYTUNNEL, 1);
it works for me,I'm testing this code as well
good luck

Categories