get response from remote server using ip board - php

i want to get data from remote API with curl but not works:
(im using ip board btw)
$url = "http://www.voobly.com/api/findusers/". $nick_list . "?key=" . $voobly_key;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
this is the response i get:
Please enable cookies. One more step
Please complete the security check to access www.voobly.com
Why do I have to complete a CAPTCHA?
Completing the CAPTCHA proves you are a human and gives you temporary
access to the web property.
What can I do to prevent this in the future?
If you are on a personal connection, like at home, you can run an
anti-virus scan on your device to make sure it is not infected with
malware.
If you are at an office or shared network, you can ask the network
administrator to run a scan across the network looking for
misconfigured or infected devices.
Cloudflare Ray ID: 3b009b3171e55c09 • Your IP: 69.89.31.238 •
Performance & security by Cloudflare
anyone know how to solve this
API provider said i need to add a valid browser agent string + PHP cookie session but idk what wrong here :(

The web site you're trying to access has misconfigured Cloudflare to block bots from accessing their site… including the API.
You will need to contact them to have them disable this. There is no easy workaround -- the whole point of this feature is to prevent scripts from accessing the site.

Related

PHP CURL: Instagram returns empty string to remote server

I found out that I can get latest user posts in JSON format with a simple CURL request to
https://www.instagram.com/some_nickname/?__a=1
So I am trying:
$url = 'https://www.instagram.com/some_nickname/?__a=1';
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
$response = curl_exec($curl);
The code works fine on my local machine and returns a JSON array, from which I get the latest posts of a user. The problem is that the very same code returns empty string from any of my remote servers (I've tried 3 different web-hosting providers).
Please, advice.
Instagram blocked the ranges of IP hostings. I have seen the following information:
Instagram has started applying extremely restrictive limits to
requests from IPs that are detected as cloud servers.
A couple of requests will go through at first, but after a moment, all
requests will be blocked, with a very long timer until they are
unblocked again. After this timer, you get a couple more requests, and
the cycle repeats.
Since websites must be hosted in the cloud, any interaction with
Instagram becomes extremely difficult if the cloud provider is on
Instagram's block list. All the cloud providers I've tried are on that
list.
You need to use proxy. But it will be a difficult task, because many proxy(in my experience) are also blocked

PHP cURL not working when send POST request to fetch data

I am recently working on a project on which I need to scrape some data from an external website. It is working on Localhost but stopped working on the live host. I explored on google as well on StackOverflow where people suggested that open PHP curl extension etc but everything already opened because I am doing a lot more scraping on that hosting which is working as cake.
Code is
$url = "https://pakesimdata.com/sim/search-result.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, "cnnum=3005210911");
echo $html = curl_exec($ch);
When I echo the result with URL https://pakesimdata.com/sim/search.php or https://pakesimdata.com/ I got the result but it is not working when I do the POST request to acquire the result on URL https://pakesimdata.com/sim/search-result.php. It shows me nothing. I also do the error handling but got no luck, gave no error which put me a great headache. I can not grab what's going on and on which section I need to work to get the results.
It is working on Localhost but stopped working on the live host.
This would suggest two possibilites
1.) Your host does not like outgoing http connections which you rules out already
2.) The remote host does not like your scraping
ad 2.)
Can it be they have blocked your IP address or some other mechanism is protecting the page from beeing used by your script as usually operators of services like this do not like to be scraped by bots.
LOCALHOST will probably appear as your own private IP address with probably a dynamic
always changing IP address - like an ordinary user.
Your real server will have a fixed IP adress and probably the external website analzes the traffic and blocks ip adresses for abuse if a lot of requests are coming from the same IP.

Accessing googleapis fails

My user logs into my app, app sends idtoken to my server, server sends request to google, google sends userdata to my server, server puts it in my db. worked fine for 5 Months.
Now:
If I type in my webbrowser
https://www.googleapis.com/oauth2/v3/tokeninfo?id_token= (+ idtoken of my google account extracted from my app)
I'll get the json with my name and so on in milliseconds as it should be.
today, since 6 hours, if my phpfile runs the command
$url = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=".$idtoken;
$str =file_get_contents($url);
The page is loading and loading and finally returns no value.
I tried this version to get the .json file
$ch = curl_init($url); // such as http://example.com/example.xml
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$str= curl_exec($ch);
curl_close($ch);
no fix with that.
I cannot install composer because no root access.
I contacted customer support, they told me everything is fine on the serverside.
If after checking on the server's console that you can't curl to it over SSL, but can otherwise, it would suggest the port is blocked. Ask the hosting provider to open it.

PHP: How to use cURL to interact back and forth with hardware device?

I'm familiar with cURL for retrieving files, submitting POSTs, etc, but now I need a php script to "chat" with a networked hardware device. This device has a kind of Terminal Mode and is accessible through a shell with tools like netcat. I'm trying to reproduce that dialog with a php script.
So far I can open the connection and get the password request:
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, 'http://192.168.0.35:4025');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
echo "DSC: $result \n";
// submit password
// read answer to see if password is approved
// submit command
// get command answer
curl_close($ch);
How can I now submit the password as a single string, over that existing cURL connection, and keep my script interacting back and forth sending and receiving strings?
Is there a better tool than cURL for this?
The plan is to keep the connection alive forever, for monitoring purposes.
Any assistance will be appreciated.
you can use socket check this
Socket : sockets are the fundamental "things" behind any kind of network communications done by your computer. For example when you type www.google.com in your web browser, it opens a socket and connects to google.com to fetch the page and show it to you. Same with any chat client like gtalk or skype. Any network communication goes through a socket.

cURL can't connect in a free host but works fine in my localhost

I created a small web app, with the feature of being able to Sign in with a Twitter account, by connecting with OAuth. It worked like charm for a few months, but now it stopped working. This is a quick and summarized overview "Sign in with twitter" algorithm.
Collecting some parameters (timestamp, nonce, some kind of application ID and so)
Use this parameters to create a new URL that looks like this:
https://api.twitter.com/oauth/request_token?oauth_consumer_key=DLZZTIxpY19FnWJNtqw5A&oauth_nonce=1369452195&oauth_signature=DIetumiKqJu66XXVvDDHdepnP9M%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1369452195&oauth_version=1.0
Connect to that URL and retrieve the data, it has an access token
Continue doing fun stuff using that access token.
The URL generated in step 2 is fine because I tried manually copying it in Google Chrome, and it shows a beautiful access token, so the problem isn't there (I think).
In the step 3, I have a really small method that should do some very basic stuff: Connect to the URL generated before, retrieve the content and return it.
In my localhost Using EasyPHP 12.1, it works perfectly, as usual, but in the free host that i'm using (000webhost) it doesn't work anymore. When trying to connect, it just timeouts. The HTTPCodeError is 0 and the CurlError is "Couldn't connect to host".
This is the method used to connect to the URL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$response = curl_exec($ch);
curl_close($ch);
return $response;
And this is an example of a URL used with that method:
https://api.twitter.com/oauth/request_token?oauth_consumer_key=DLZZTIxpY19FnWJNtqw5A&oauth_nonce=1369452195&oauth_signature=DIetumiKqJu66XXVvDDHdepnP9M%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1369452195&oauth_version=1.0
I've been trying to fix it all day long, but now I have no idea even of what to try. The files are the very same in my localhost and in the 000webhost.
If you could enlighten me I would be very happy. I'll take my pants off for answers if it's needed. Thank you very much.
It might be possible that Twitter has blacklisted (blocked) your free host's servers or IP address. This can happen if other users on the server abuse the API.
The only thing I can think of is that your free web hosting service blocks it. You know these services are perfect as long as everything is very simple. The moment things become complicated you run into restrictions implemented by the provider. Most of these services limit band width, disk space, server use, support, uploading and more.

Categories