Web Development and Design | Tutorial for Java, PHP, HTML, Javascript: Curl

Web Development and Design | Tutorial for Java, PHP, HTML, Javascript: Curl
Showing posts with label Curl. Show all posts
Showing posts with label Curl. Show all posts

PHP Curl Post Tutorial

PHP Curl Post Tutorial

PHP Curl Post Tutorial


Code : - 
<?php
$url="https://reqres.in/api/users";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,"name=test&job=dev");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$html=curl_exec($ch);
echo $html;
?>

This is same as loading a webpage using php curl here in this we set two more option. 1.post=true for posting data 2.postfields = which is our post data.

Video Tutorial

1

PHP Curl Load Simple Webpage

PHP Curl Load Simple Webpage

PHP fetch web page using curl

Code : - 

<?php
$url="https://jsonplaceholder.typicode.com/posts";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$html=curl_exec($ch);
echo $html;
?>

In 2nd line we define our webpage which we have to fetch.
Then in 3rd line we initialize our curl.
In 4th line we set option for curl like url and return transfer etc.
Then we execute our curl and fetch the webpage.

Video Tutorial

0