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 : muhammad-ishaq
$url="http://abc/api/xyz.php"; //url of 2nd website where data is to be send
$postdata = $data
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0)
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Content-Type', 'application/json'));
$result = curl_exec ($ch);
echo $result;
curl_close($ch);
Source : | Last Update : Tue, 19 Jul 22
Answered by : cheerful-cow-r45o49elrf4g
// Initialize Curl $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://coinmarketcap.com/"); // set live website where data from curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // default curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // default $content = curl_exec($curl); preg_match_all('!<p color="text3" class="sc-AxhUy bzeXdk coin-item-symbol" font-size="1">(.*?)</p>!', $content, $matches); var_dump($matches);
Source : https://youtu.be/-jiMnIwtcuk | Last Update : Fri, 12 Mar 21
Answered by : blueeyed-barracuda-ccthaiq5xm77
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
//check the result
var_dump($result);
Source : https://www.wpoven.com/tutorial/how-to-pass-post-variables-via-php-curl/ | Last Update : Mon, 23 Aug 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