Johnson Smith
Johnson Smith

Reputation: 55

How to fetch a webpage with php curl and display that webpage html?

i am new to php and i want to get a webpage html through the use of php curl...i am not getting the output,am just getting a white page. Can anyone please help?

<?php 
$url=$_POST['txturl'];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$output = curl_exec($ch);
echo $output;
curl_close($ch); 
?>

Upvotes: 2

Views: 14845

Answers (1)

You don't need to send URL twice

<?php 
$url=$_POST['txturl'];
$ch = curl_init();//I have removed it from here
curl_setopt($ch, CURLOPT_URL,$url);// This will do
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$output = curl_exec($ch);
echo $output;
curl_close($ch); 
?>

Check if you really have cURL Installed

<?php
echo function_exists('curl_version')?'Yes':'No';
?>

Upvotes: 6

Related Questions