<?php
$ch = curl_init("https://www.snai.it/sport"); // initialize curl handle
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
print($data);
?>
I wan't to fetch this page using php curl.it gives the empty response and there is no error in the console I don't know what is going wrong any help will be appreciated.
Your url redirects to a secured page (i.e. https page). Probably you do not have any ssl support for your curl. I used verbose mode curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
and it came on response:
< HTTP/1.1 302 Found
< Location: https://www.snai.it/
< Connection: close
curl_exec()
returns TRUE
on success or FALSE
on failure by default.
If you want to get the result/data from the given URL you will need to set the CURLOPT_RETURNTRANSFER
option.
So add following line before curl_exec()
.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
As mentioned by @Sabuj one will also need to add following to fetch the redirect secure page.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);