Reputation: 13
My goal is to make a get request to a specified url
without a redirect and without a visual difference in the website. I want to make a get request like <img src="http://www.google">
does, which is without a redirect, silent in the background and without a visual difference in the page it is executed on.
Here is my code:
$curl_handle = curl_init();
curl_setopt( $curl_handle, CURLOPT_URL, 'http://www.google.com' );
curl_setopt( $curl_handle, CURLOPT_FOLLOWLOCATION, 0);
curl_exec( $curl_handle );
curl_close( $curl_handle );
Now the problem with the above php
code is that when it is run, the main page of http://www.google.com is loaded onto the page similar to an iframe
. So my question is, how can i stop that from happening? How can i make the get request without any visual difference just like <img src="http://www.google.com">
does?
Upvotes: 1
Views: 735
Reputation: 7888
Use CURLOPT_RETURNTRANSFER
option to get content of requested URL instead of printing it to web page.
$curl_handle = curl_init();
curl_setopt( $curl_handle, CURLOPT_URL, 'http://www.google.com' );
curl_setopt( $curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $curl_handle, CURLOPT_FOLLOWLOCATION, 0);
curl_exec( $curl_handle );
curl_close( $curl_handle );
Upvotes: 2