I have two Servers:
1. Licensing
2. Provisioning
Now a client(android/ios device) sends a request to license server. So there we get some parameters from GET which I want to forward to Provisioning server, using CURL.
This code is on License Server
$skey = $this->input->get('site_id');
$uid = $this->input->get('user_id');
$url = "http://127.0.0.1/provisioning/customer/provisioning?site_key=".$skey."&uid=".$uid;
$wget_cmd = "wget --no-check-certificate \"".$url."\" >/dev/null 2>/dev/null ";
//echo($wget_cmd);
//exec($wget_cmd);
// create a new cURL resource
$ch = curl_init();
//curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
echo curl_error($ch);
// close cURL resource, and free up system resources
curl_close($ch);
On the Provisioning Server How to access these variables?:
$skey = $this->input->get('site_id');
$uid = $this->input->get('user_id');
I don't want to echo them on screen I Just want to use them for other DB transactions.
Related
I'm trying to grab cookies from a remote host with a little script which works well:
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_COOKIE, TRUE);
// grab URL and pass it to the browser
$opt = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
I would like to know how I can pass them back to the client?
I have two Servers:
1. Licensing
2. Provisioning
Now a client(android/ios device) sends a request to license server. So there we get some parameters from GET which I forward to Provisioning server, using CURL like this:
$skey = $this->input->get('site_id');
$uid = $this->input->get('user_id');
$url = "http://127.0.0.1/example.com?site_key=".$skey."&uid=".$uid;
$wget_cmd = "wget --no-check-certificate \"".$url."\" >/dev/null 2>/dev/null ";
//echo($wget_cmd);
//exec($wget_cmd);
// create a new cURL resource
$ch = curl_init();
//curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
echo curl_error($ch);
// close cURL resource, and free up system resources
curl_close($ch);
Now the provisioning server has a file called provisioning.php. There I perform some DB operations based on the request from License server and generate a URL which I want to send back to the license server.
On provisioning I generate a URL like this based on DB operations:
$uri = site_url('/uploads/'.$user_ini['custom_ini_filename'].'.ini');
$ini_url = json_encode($uri,JSON_UNESCAPED_SLASHES);
Here I want to return this $ini_url back to license server.
How do I do this?
How to access this $ini_url on the license server ?
Set CURLOPT_RETURNTRANSFER to 1 and simply assign the response from curl_exec($ch) to a variable:
License Server
$skey = $this->input->get('site_id');
$uid = $this->input->get('user_id');
$url = "http://127.0.0.1/example.com?site_key=".$skey."&uid=".$uid;
$wget_cmd = "wget --no-check-certificate \"".$url."\" >/dev/null 2>/dev/null ";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLOPT_URL, $url);
// The blow variable stores the response from provision server
$response_from_provision_server = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
You will also need to echo the contents of $ini_url from the provision server, this being the output that is sent back to License Server in response to the curl_exec() call.
Provisioning Server
$uri = site_url('/uploads/'.$user_ini['custom_ini_filename'].'.ini');
$ini_url = json_encode($uri,JSON_UNESCAPED_SLASHES);
// echo the $ini_url variable
echo $ini_url;
i am using with curl libary to scrape web site.
when i am using proxy nothing now shown.
i took the ip proxy from hide my ass list.
here is my code. someone can tell me what is wrong ?
$url = 'http://www.sherut24.co.il';
$proxy = '189.218.145.44:10000';
$ch = curl_init(); // Initialise a cURL handle
// Setting proxy option for cURL
// Set any other cURL options that are required
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$results = curl_exec($ch); // Execute a cURL request
curl_close($ch); // Closing the cURL handle
echo $results;
I am trying to fetch data from an API with cURL for PHP.
When I execute following script, cURL doesn't seem to wait for the request.
It immediately returns the empty field, which couldn't be populated.
function request($cityName)
{
$key = "abc";
$api = "https://...?api-key=$key&format=json&city=$cityName";
$api = urldecode(trim($api));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $api);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERAGENT, 'abc.com');
$ret = curl_exec($curl);
$response = json_decode($ret);
var_dump($response);
curl_close($curl);
}
Try this, don't use urldecode
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($curl, CURLOPT_USERAGENT, 'abc.com');
$server_output = curl_exec($ch);
curl_close($ch);
print_r($server_output);
The OAuth extension uses curl to make the request. By default CURL will generally verify the SSL certificate to see if its valid an issued by an accepted CA. To do this, curl uses a bundled set of CA certificates.
You can either disable the SSL checks ($oauth->disableSSLChecks()). Or ensure that you have a current version of curl. More information on curl certification verification.
There are chances that the cURL cancels the request because of low speed connetction.
This happens if the average transfer rate drops below CURLOPT_LOW_SPEED_LIMIT bytes/second for CURLOPT_LOW_SPEED_TIME seconds.
Try the following:
curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1); // cancel cURL if below 1 byte/second
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 30); // Wait for 30 seconds
Change the values of the above options according to your requirements.
$url = 'http://dynupdate.no-ip.com/ip.php';
$proxy = '127.0.0.1:8888';
//$proxyauth = 'user:password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo $curl_scraped_page;
How would I make this continuously connect to this server?
I'm working on a bot for this site to improve the technology. Also, how would I authenticate cookies on the server, for example: I send a request to the server with this script using the certain cookies I would like to use.
There is an option called CURLOPT_COOKIEJAR where you can set the file that contains the cookie:
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
Once you get the cookie you have to use the same $ch variable to keep the connection.
You can found a complete example of cURL usage here: http://blog.binacube.com/2014/08/complete-curl-example-login-proxy-and.html