is their an option to save the outpout of a curl request in a php variable?
Because if i only save the $result i get a 1 or nothing
<?php
$url='http://icanhazip.com';
$proxy=file ('proxy.txt');
$useragent='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)';
for($x=0;$x<count($proxy);$x++)
{
$ch = curl_init();
//you might need to set some cookie details up (depending on the site)
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_URL,$url); //set the url we want to use
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
curl_setopt($ch, CURLOPT_PROXY, $proxy[$x]);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); //set our user agent
$result= curl_exec ($ch); //execute and get the results
print $result; //display the reuslt
$datenbank = "proxy_work.txt";
$datei = fopen($datenbank,"a");
fwrite($datei, $result);
fwrite ($datei,"\r\n");
curl_close ($ch);
}
?>
php $url = 'hxxp://domain.com/univ/v8?q=tas+wanita'; $ch=curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $r=curl_exec($ch); curl_close($ch); print_r(json_decode($r, true)); ?>
cURL is a PHP extension that allows you to use the URL syntax to receive and submit data. cURL makes it simple to connect between various websites and domains. Obtaining a copy of a website's material. Submission of forms automatically, authentication and cookie use.
PHP $url = "http://www.ecs.soton.ac.uk/news/"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $html = curl_exec($ch); $status_code = curl_getinfo($ch,CURLINFO_HTTP_CODE); if($status_code=302 or $status_code=301){ $url = ""; // I want to to get the destination url } ...
This is a short PHP tutorial on how to return cURL output as a string. As you probably already know, the default behavior of cURL is to simply print the response out onto the page. However, there is a quick fix for this. The CURLOPT_RETURNTRANSFER option. The curl_setopt function allows you to configure various options for a cURL request.
is their an option to save the outpout of a curl request in a php variable? Search "CURLOPT_RETURNTRANSFER" in here. You need to set CURLOPT_RETURNTRANSFER option to true. With this you can avoid the output and make the programme continue running. Not the answer you're looking for?
One is directly calling function by variable name using bracket and parameters and the other is by using call_user_func () Function but in both method variable name is to be used. echo $msg." "; Another Method: Using eval () Function: The eval () function is an inbuilt function in PHP which is used to evaluate string as PHP code.
I was hoping to curl data into a shell script variable, then use cat or awk to operate on that variable as if it were a file. Is this possible, or is there a workaround? Sure you can.
You need to set CURLOPT_RETURNTRANSFER
option to true.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
You need to add a setting of curl option CURLOPT_RETURNTRANSFER:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
With this you can avoid the output and make the programme continue running.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With