我的目标是向指定的url
发出get请求,而无需重定向,并且在网站中没有视觉差异。我想像<img src="http://www.google">
那样发出一个get请求,它没有重定向,在后台静默,在执行它的页面上没有视觉差异。这是我的代码:
$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 );
现在,上面的php
代码的问题是,当它运行时http://www.google.com被加载到类似于CCD_ 4的页面上。所以我的问题是,我该如何阻止这种情况的发生?如何像<img src="http://www.google.com">
那样在没有任何视觉差异的情况下发出get请求?
使用CURLOPT_RETURNTRANSFER
选项获取请求URL的内容,而不是将其打印到网页上。
$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 );