Site icon Nabtron

[Solved]How to get content of page using PHP cURL – simple

phpThis tutorial explains how to get the content of a page using PHP cURL.

This is a perfectly working example, you just need to change the “url” value which can be either entered by hand there or made dynamic variable if it “GET” or “POST” the value from the submitted data to that page.

The output of the page content comes out as $output which you can either echo (to show the content of the page on that scripts page or else use it as you want.

<?php
$url = "http://nabtron.com";
$cookie = tmpfile();
$userAgent = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31' ;

$ch = curl_init($url);

$options = array(
CURLOPT_CONNECTTIMEOUT => 20 ,
CURLOPT_USERAGENT => $userAgent,
CURLOPT_AUTOREFERER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIEFILE => $cookie,
CURLOPT_COOKIEJAR => $cookie ,
CURLOPT_SSL_VERIFYPEER => 0 ,
CURLOPT_SSL_VERIFYHOST => 0
);

curl_setopt_array($ch, $options);
$output = curl_exec($ch);
curl_close($ch);
//you can echo or do whatever to the variable $output now here onwards
?>

Hope it works for you to get and show / use the content of the webpage using curl.

Exit mobile version