For this question, google and Baidu are all in a long article of english, which is really a headache if you are not proficient in linux. The solution is actually very simple. 301 redirection
Use php curl to obtain remote files. the code is as follows:
$ Ghurl = isset ($ _ GET ['id'])? $ _ GET ['id']: 'http: // www.baidu.com /'; // Php get Function getContents ($ url ){ $ Header = array ("Referer: http://www.baidu.com /"); $ Ch = curl_init (); Curl_setopt ($ ch, CURLOPT_URL, $ url ); Curl_setopt ($ ch, CURLOPT_TIMEOUT, 30 ); Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header ); Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); // whether to capture the redirected page Ob_start (); Curl_exec ($ ch ); $ Contents = ob_get_contents (); Ob_end_clean (); Curl_close ($ ch );
Return $ contents; }
$ Contents = getContents ($ ghurl ); Echo $ contents; ?>
|
Generally, in win2003 + iis, if you configure php_curl.dll, it will be okay.
However, in linux + apahe2.0 + php5.2.12 + directadmin (this configuration is generally used by foreign host providers), if the obtained url has a 301/302 jump, an error is returned:
Curl_setopt () [function. curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in *** |
For this question, google and Baidu are all in a long article of english, which is really a headache if you are not proficient in linux.
The solution is actually very simple: log on to yourDirectadmin
Choose> "PHP SafeMode Configuration" --> view
Set the defaultDefault SafeAndDefault Open BaseDirBothOFFThe problem is solved.
Related reading:
PHP-based cURL quick start
PHP curl Sina Weibo mail sending interface
PHP uses CURL to synchronously capture multiple webpages
PHP curl implements get and post