PHP - CURLOPT_PROXYPORT issue - php

I am so confused about my cURL script requesting the target page "facebook.com" for example, with the same port as the proxy.
example:
proxy is: 178.215.111.70:9999 . a cURL error says:
Failed connect to facebook.com:9999; Connection timed out
I see that it tries to connect to facebook using the poxy's port: 9999
Here is my code:
<?php
$curl = curl_init("https://facebook.com");
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_REFERER, 'https://www.facebook.com');
if ($var) {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, "test");
}
curl_setopt($curl, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($curl, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT ,9999999);
curl_setopt($curl, CURLOPT_TIMEOUT, 0);
curl_setopt($curl, CURLOPT_PROXY, '178.215.111.70');
curl_setopt($curl, CURLOPT_PROXYPORT, '9999');
$result['exe'] = curl_exec($curl);
$result['err'] = curl_error($curl);
curl_close($curl);
echo $result['err'];
echo $result['exe'];
?>

I solved my problem.
It was a problem in the server only. When i tried the SAME script in another server it worked 100% fine
So always make sure of the configuration in your server when you face a problem like this.

Related

Same cURL code, different results with PHP and Laravel

When I try to save cookies without Laravel,it's saved.But with Laravel I can't find the cookie file(Searched everywhere :) ).
Here is the code(part):
...Some php code...
$dataJSON = json_encode($dataPost);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $dataJSON);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, "cookie.txt"); //even with the realpath ,no difference
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($curl);
print_r($result);
curl_close($curl);
Is it a Routing problem?

cUrl working fine on localhost but it's not working on server and only shows blank page

When I run the below code on server it only shows the blank page and suddenly stop further execution, I also checked the cUrl on server which is installed.
Here is my code.
$ftp_server = 'ftps://'.'server/Voorraadtonen link.csv';
$ch = curl_init(str_replace(" ","%20",$ftp_server));
curl_setopt($ch, CURLOPT_URL, $ftp_server);
curl_setopt($ch, CURLOPT_USERPWD,'username'.':'.'password');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
curl_setopt($ch, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
//curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_PORT, 990);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_setopt($ch, CURLOPT_VERBOSE,true);
$output = curl_exec($ch);
$error_no = curl_errno($ch);
echo $output; exit;
Latest update!
You have more than 1 errors in your codes,
you are using FTPS in url which requires SSL verification, and its false in
your codes.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
//Dont use try! you shouldnt use
curl_setopt($ch, CURLOPT_FTP_SSL, CURLFTPSSL_TRY);
They should be true : SSL doesnt support true so they should be like following on #dharman warn in another answer.
But turning ssl true will require another setup like cacert file
etc. lik so
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
//and include cacert.pem
curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
Download cacert file here : https://curl.haxx.se/docs/caextract.html
2.Your url is not a true url $ftp_server = 'ftps://'.'server/Voorraadtonen link.csv';, this url will get nothing, but it should return an error atleast in error_log file, as you said all errors reporting are enabled
3.Your code should look like this
$curl = curl_init();
$file = fopen("link.csv", 'w');
curl_setopt($curl, CURLOPT_URL, "ftp://ftp.site.com/link.csv");
//Make sure for correct url
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
//Make sure for correct url
curl_setopt($curl, CURLOPT_FILE, $file);
curl_setopt($curl, CURLOPT_USERPWD, "$_FTP[username]:$_FTP[password]");
//Make sure for your ftp credentials
curl_setopt($curl, CURLOPT_TIMEOUT, 20); //20 seconds will be enough
curl_exec($curl);
echo curl_errno($ch);
echo curl_error($ch);
curl_close($curl);
fclose($file);
1 more thing left headers should not be required but in case its required.
curl_setopt($curl, CURLOPT_HEADER, false); //Or
curl_setopt($curl, CURLOPT_HEADER, true);
Now it should work without any problem
NOTE : Example code is a working example you can edit it to your requirements
UPDATE : After modification you said you did in your codes (Still not showing us), finaly we get an error. once again I am asking you to add modified code into your question.
Error_no 28 cURL error 28: Connection timed out
the cURL 28 error occurs when the cURL request isn’t completed in a certain amount of time.
This happens when the cURL timeout value is set too low or when a firewall is blocking the cURL request.
Another possibility is a security module, for example the Apache mod_security module.
To fix the cURL error 28 you can contact your hosting provider.
So basicaly!
Your server is blocking. your credentials not match to required
credentails. SSL is required by server, but you are not setting it up.
Your function runing max of your Server Memory Limits settings.
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "ftp.site.com/link.csv");
//make sure your path to file is correct
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, "$_FTP[username]:$_FTP[password]");
//make sure your login credentials correct
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
//Set timeout for connection
curl_exec($curl);
echo curl_errno($ch);
echo curl_error($ch);
//Get errors
curl_close($curl);
//Importand close curl connection.

Error using curl php, getting http status 500

Hello stackoverflow community, I am having some problems when I try to send a request with curl in php, but something odd is that I have 2 servers, and when I use my code in one of them I get the response Im looking for, but in the other one I get the following response:
Http status code 500
As you can see it says "HTTP Status 500 - empty String", but why is that? in the other server I am not getting that with the same code
Thanks in advice to anyone who can help me out!
Ok mistake by no posting my code, here it is
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_REFERER, $_SERVER['HTTP_HOST']);
curl_setopt($curl, CURLOPT_POST, 1);
//curl_setopt($curl, CURLOPT_PORT, 443);
curl_setopt($curl, CURLOPT_POSTFIELDS, $string_data);
curl_setopt($curl, CURLOPT_TIMEOUT, 300);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);

Hostgator issue with curl: SSL connect error, error no: 35

I am trying to send curl request to another domain, returns
ssl connection error with error no. 35 on hostgator.
Code:
$url= $endpoint . "?".http_build_query($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
$res = curl_exec($curl);
if(curl_error($curl))
{
echo curl_errno($curl);
echo 'error:' . curl_error($curl);
}
This issue is specific to hostgator
Please let me know how can I get rid of the ssl error
Use boolean value instead of 0 or 1 in place of $value field
Syntax - bool curl_setopt ( resource $ch , int $option , mixed $value )
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_FORBID_REUSE, true);
curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
Note:
Better use the
default(CURL_SSLVERSION_DEFAULT). Setting it to CURL_SSLVERSION_TLSv2
or CURL_SSLVERSION_TLSv2 is very dangerous given the known
vulnerabilities in SSLv2 and SSLv3.
Reference:- http://php.net/manual/en/function.curl-setopt.php

cURL: Operation timed out after 0 milliseconds

cURL gives me the error:
Operation timed out after 0 milliseconds with 0 out of 0 bytes received
In particular, the "0 milliseconds" part is suspicious...
My initialization code:
$curl = curl_init($requestUrl); // private URL not published
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-Type: application/xml", "Accept: application/xml"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_HTTP200ALIASES, range(400, 599));
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
The timeout seems correctly set, what may be related it?
I had the same issue, when tried to connect via https. Problem was with ssl version.
This worked well for me:
$ch=curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);

Categories