I will give you some examples you can Just copy and paste in your PHP file to check.
First this is my favorite and most efficient way to get information from other webpages or even insert information if you need to.
GET RESULTS FROM WEBPAGE BY GET METHOD(It would work for the work you need):
$ch = CURL_INIT();
$url = 'https://google.com';
CURL_SETOPT($ch, CURLOPT_URL, $url );
//CURL_SETOPT($ch, CURLOPT_PROXY, $ip); //IN CASE YOU NEED TO USE PROXY
//CURL_SETOPT($ch, CURLOPT_PROXYPORT, $port);
CURL_SETOPT($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0');
CURL_SETOPT($ch, CURLOPT_POST, 0);//Get instead of post
CURL_SETOPT($ch, CURLOPT_RETURNTRANSFER, True);
CURL_SETOPT($ch, CURLOPT_FOLLOWLOCATION, True);
CURL_SETOPT($ch, CURLOPT_ENCODING, 'gzip, deflate');//Try to curl https://amazon.com WITHOUT THIS LINE, it would give you some extra encryption.
CURL_SETOPT($ch, CURLOPT_CONNECTTIMEOUT,90);
CURL_SETOPT($ch, CURLOPT_TIMEOUT,90);
$result = CURL_EXEC($ch);
echo $result;
Next is if you need to insert data in the page using a post method.
You can use this to LOG IN in some websites or you use to insert and get data automatically
$data = array(
"email" => "example@gmail.com",
"pwd" => "12341234",
"some other field"=> '123123'
);
$ch = CURL_INIT();
$url = 'https://google.com';
CURL_SETOPT($ch, CURLOPT_URL, $url );
CURL_SETOPT($ch, CURLOPT_POST, true); //Post request
CURL_SETOPT($ch, CURLOPT_POSTFIELDS, $data);
CURL_SETOPT($ch, CURLOPT_RETURNTRANSFER,True);
CURL_SETOPT($ch, CURLOPT_FOLLOWLOCATION,True);
CURL_SETOPT($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) ."/cookie.txt");//I am saving here the cookies in case I need to go to another page or do some action after login
CURL_SETOPT($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) ."/cookie.txt");
CURL_SETOPT($ch, CURLOPT_FOLLOWLOCATION, true); //ALLOW REDIRECTION
CURL_SETOPT($ch, CURLOPT_CONNECTTIMEOUT,90);
CURL_SETOPT($ch, CURLOPT_TIMEOUT,90);
$result = CURL_EXEC($ch);
Second it is the most easy one that has some limitations and because of that I don't like:
$url = 'https://www.google.com/';
echo file_get_contents($url);
If you have any questions, let me know.
I work with curl all the time!