Last updated on November 28th, 2022 at 08:19 am

A very simple usage of curl to get a webpage content in to a variable, here we are using functions of curl namely curl_setopt and curl_exec

Web page we are loading here is ‘upload.php‘, What CURL basically do here is open the page, get the output of that page by executing curl_exec and assign it to variable $output.
Find the code below.

$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, "http://localhost/lic/upload.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$output = curl_exec($ch);
curl_close($ch);
echo $output;

Save the above script inside a file with the name curl_check.php. Once the webpage is loaded we will get the contents of localhost/lic/upload.php inside curl_check.php

You might also be interested in this tutorial Check if web page exists using PHP

Leave a Reply

Your email address will not be published. Required fields are marked *