Answered by : rafael
// set post fields
$post = [ 'username' => 'user1', 'password' => 'passuser1', 'gender' => 1,
];
$ch = curl_init('http://www.example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// execute!
$response = curl_exec($ch);
// close the connection, release resources used
curl_close($ch);
// do anything you want with your response
var_dump($response);
Source : https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code | Last Update : Fri, 22 May 20
Answered by : code-grepper
function getUrl($url){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec($ch); curl_close($ch); return $response;
}
Source : | Last Update : Wed, 03 Jul 19
Answered by : foolish-ferret-knhaa2hlx4e8
$ch = curl_init();
$curlConfig = array( CURLOPT_URL => "http://www.example.com/yourscript.php", CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => array( 'field1' => 'some date', 'field2' => 'some other data', )
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
// result sent by the remote server is in $result
Source : https://stackoverflow.com/questions/2440252/php-curl-i-need-a-simple-post-request-and-retrival-of-page-example | Last Update : Tue, 28 Sep 21
Answered by : sigge-arkestl
<?php
// 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, 0);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
?>
Source : https://www.php.net/manual/en/function.curl-init.php | Last Update : Wed, 31 Aug 22
Answered by : martin-mladenov-2lnvs7ib3riv
function curl( string $url, array $data)
{ function send($url, $request) { $ch = curl_init(); $headers = [ 'Accept: application/json', 'Content-Type: application/json', ]; $options = [ CURLOPT_URL => $url, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $request, CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => $headers, ]; curl_setopt_array($ch, $options); $response = curl_exec($ch); curl_close($ch); return $response; } return send($url, json_encode($data));
}
Source : | Last Update : Tue, 05 Jul 22
Answered by : amrinder-singh-bajwa
function &web_curl_http($url)
{ $c = curl_init(); curl_setopt( $c , CURLOPT_URL , $url); curl_setopt( $c , CURLOPT_USERAGENT, "Mozilla/5.0 (Linux Centos 7;) Chrome/74.0.3729.169 Safari/537.36"); curl_setopt( $c , CURLOPT_RETURNTRANSFER, true); curl_setopt( $c , CURLOPT_SSL_VERIFYPEER, false); curl_setopt( $c , CURLOPT_SSL_VERIFYHOST, false); curl_setopt( $c , CURLOPT_TIMEOUT, 10000); // 10 sec $data = curl_exec($c); curl_close($c); return $data;
}
Source : https://stackoverflow.com/questions/58674511/simple-php-curl-get-request-not-working-at-all | Last Update : Fri, 17 Jun 22
Answered by : karan-mehta-8dc1x4jfp7we
$ch = curl_init();
$curlConfig = array( CURLOPT_URL => "http://www.example.com/yourscript.php", CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => array( 'field1' => 'some date', 'field2' => 'some other data', )
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
Source : | Last Update : Wed, 10 Aug 22
Answered by : dfg
$ch = curl_init('http://example.com/image.php');
$fp = fopen('/my/folder/flower.gif', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
Source : https://stackoverflow.com/questions/724391/saving-image-from-php-url | Last Update : Thu, 28 Jul 22
Answered by : ibrahim-hammed
$data = json_encode(array( "ShortCode" => "600981", "ResponseType" => "Completed", "ConfirmationURL" => "https://mydomainx.com/confirmation", "ValidationURL" => "https://mydomainx.com/validation",
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
Source : https://stackoverflow.com/questions/71117386/how-do-i-punctuate-php-curl-statements/71117584#71117584 | Last Update : Mon, 07 Mar 22