How To Bypass Cloudfare using php or javascript - php

My problem is
I have made curl request on paxfull api earlier it was returning result but now its returning 503 .
Here is my code
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, 'https://paxful.com/buy-bitcoin?format=json');
curl_setopt($handle, CURLOPT_POST, false);
curl_setopt($handle, CURLOPT_BINARYTRANSFER, false);
curl_setopt($handle, CURLOPT_HEADER, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 10);
$response = curl_exec($handle);
$hlength = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
$body = substr($response, $hlength);
// If HTTP response is not 200, throw exception
if ($httpCode != 200) {
throw new Exception($httpCode);
}
I get this error:
Error Fatal error: Uncaught exception 'Exception' with message '503'
I googled and found it might be ip address blocked but when made get request at browser its giving results to me.
now i came with conclusion they are not allowing any GET Request .
if you run url https://paxful.com/buy-bitcoin?format=json it first check browser the return the result.
how can we get results of paxfull api. please suggest
here is snapshot
then there api redirects 404
url http://localhost/cdn-cgi/l/chk_jschl?jschl_vc=c5b74eae14eb1b1e5862f913b9f0f178&pass=1499953121.017-h%2FljgkjMr%2B&jschl_answer=18913
Its not possible through javascript also
fiddle http://jsfiddle.net/00cvyyuo/350/
i found link How to bypass cloudflare bot/ddos protection in Scrapy?
but this link helps in python so can someone help in php or javascript.

try to use Chrome's network tab in Developer Tools(f12) to see the actual request being sent. If it works then try to repeat the request from a REST client, where you can edit the headers to check what works and what not.
If you got it working then set all the headers in cURL. If it fails then set verbose and check what was sent.

Related

403 response when sending POST data via cURL

I'm trying to send some data to a custom built API that was built by a web development agency. The api is pretty straight forward, and all that I require to do is authorise myself with an authorisation basic header and submit a payload which is just JSON data.
The problem is that the API is responding with 403 every time I send a POST request using cURL. Is there any way that my code could be causing this? or is it an error that is caused by the API/API server? Regardless if the JSON payload is correctly formatted or not, it should still return with a 200 response.
The request is pretty straight forward -
<?php
//I've removed the actual username and password
$headers = array(
'Content-Type: application/json',
'Authorization: Basic '.base64_encode('username:password'));
$empty_array = array();
//Create empty json as an example
$json = json_encode($empty_array);
$url = "https://website.com/import";
//start cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS,
$json);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
If I take out the POST data, then it will return with a 404 response. This is the correct behaviour if there is no POST data submitted to the url. (I get a 404 if I navigate to the url via a browser). So I have a theory that the server must have some kind of restrictions on accepting POST data.
Does my code seem correct or am I missing something glaringly obvious? I wan't to rule out that it's a problem caused by my end due to not being able to access the code/server for the API as that is beyond my control.

cURL call to web service not working

I am trying to make a simple get call to a .NET RESTful web service at https://salesgenie.com/brandingservice/details?url=att.salesgenie.com The test page making the cURL call is at https://test-cms.salesgenie.com/wp-content/themes/salesgenie/branding-proxy.php The web service can be called in the browser but is timing out when called via cURL. Here is the code from the branding-proxy.php page:
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
$url = 'https://salesgenie.com/brandingservice/details?url=att.salesgenie.com';
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($handle, CURLOPT_SSLVERSION,3);
$response = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
setcookie('CmsCookie', $code . ' ' . $response, 0, '/', 'salesgenie.com', 0);
echo 'Code:' . $code."<br />Response: ".$response;
I can see that the timeout happens while using your links, though I think the problem happens somewhere else. The reason I've come to that conclusion is that I uploaded your code to my own website. It worked fine.
Important
If you are the owner of salesgenie.com then I think you have a problem with the server, since sometimes the responses I got was either a timeout (code 0), code 200 (with result) or code 320. So the problem might be a problem within the server itself.
Tricks
Try removing the setcookie to spare some processing.
Also try using http instead of https since https requires some more processing to use.

curl error no 35 for payment gateway url

hey guys was hoping you can help me out.
I am implementing an payment gateway, and sending the request via curl by keep getting error no.
35, "Unknown SSL protocol error in connection"
It works correctly if I post a form to the url directly through my browser, gets me the right response etc, but problem is when I do it with curl.
My small, minified version of code is
$query="type=sale&username=demo&password=password&ccnumber=4111111111111111&ccexp=1013&amount=50";
$request = curl_init("https://secure.msicharge.com/api/transact.php"); // initiate curl object
curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($request, CURLOPT_POSTFIELDS, $query); // use HTTP POST to send form data
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
$data = curl_exec($request);
echo $data;
echo curl_errno($request),curl_error($request) ;
curl_close ($request);
Any ideas? thanks in advance.
You can also try this
curl_setopt($ch, CURLOPT_SSLVERSION, 3);

Handle 403 error without making redirection

I wanted to handle 403 error without using server side error redirection methods(i.e. without using .htaccess file). Sometimes server returns a 403 error message (forbidden access). So is it possible to have PHP script which handles this 403 error message?
For example, Before showing error page, I would like to obtain server status when it my specific php page runs, and without making a redirection, I would just like to display custom message in the that page.
Some solutions for you.
Check for URL errors and make sure the actual web page is specified. Its common reason for a web site to return the 403 Forbidden error, when the URL is pointing to a directory instead of a web page. Which can be done using HttpRequest Class in PHP. You can use http_get to perform GET request. You can also Test URL here.
<?php
$response = http_get("URL", array("timeout"=>1), $info);
print_r($info);
?>
Output:
array (
'effective_url' => 'URL',
'response_code' => 403,
.
and so on
)
What is important for you is response_code with which you can play further.
Use of curl.
function http_response($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$head = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if(!$head)
{
return FALSE;
}
return $httpCode;
}
$errorcode = http_response("URL"); //if success 200 otherwise different

file_get_contents throws 400 Bad Request error PHP

I'm just using a file_get_contents() to get the latest tweets from a user like this:
$tweet = json_decode(file_get_contents('http://api.twitter.com/1/statuses/user_timeline/User.json'));
This works fine on my localhost but when I upload it to my server it throws this error:
Warning: file_get_contents(http://api.twitter.com/1/statuses/user_timeline/User.json) [function.file-get-contents]:failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request...
Not sure what might be causing it, maybe a php configuration I need to set on my server?
Thanks in advance!
You might want to try using curl to retrieve the data instead of file_get_contents. curl has better support for error handling:
// make request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.twitter.com/1/statuses/user_timeline/User.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
// convert response
$output = json_decode($output);
// handle error; error output
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
var_dump($output);
}
curl_close($ch);
This may give you a better idea why you're receiving the error. A common error is hitting the rate limit on your server.
You can use file_get_contents adding the ignore_errors option set to true, in this way you will get the entire body of the response in case of error (HTTP/1.1 400, for example) and not only a simple false.
You can see an example here: https://stackoverflow.com/a/11479968/3926617
If you want access to response's headers, you can use $http_response_header after the request.
http://php.net/manual/en/reserved.variables.httpresponseheader.php
Just a little addendum on Ben's answer.
According to the PHP manual the CURLOPT_URL option may be set when inizializing the cURL handle with curl_init().
// make request
$ch = curl_init("http://api.twitter.com/1/statuses/user_timeline/User.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
// convert response
$output = json_decode($output);
// handle error; error output
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
var_dump($output);
}
curl_close($ch);

Categories