PHP Get Web Page content
PHP Get Web Page content
PHP Get Web Page content using CURL
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
You might also be interested in this tutorial Check if web page exists using PHP
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