Home Backend Development PHP Tutorial file_get_contents获取不到网页内容的解决方法_php技巧

file_get_contents获取不到网页内容的解决方法_php技巧

May 17, 2016 am 09:06 AM
file_get_contents

复制代码 代码如下:

 $url = "http://jb51.net/index.html";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
//在需要用户检测的网页里需要增加下面两行
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
//curl_setopt($ch, CURLOPT_USERPWD, US_NAME.":".US_PWD);
$contents = curl_exec($ch);
curl_close($ch);
echo $contents;
?> 
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

如何解决PHP Warning: file_get_contents(): failed to open stream: HTTP request failed 如何解决PHP Warning: file_get_contents(): failed to open stream: HTTP request failed Aug 18, 2023 pm 11:34 PM

如何解决PHP Warning: file_get_contents(): failed to open stream: HTTP request failed

How to solve PHP Warning: file_get_contents(): Filename cannot be empty How to solve PHP Warning: file_get_contents(): Filename cannot be empty Aug 18, 2023 pm 07:30 PM

How to solve PHP Warning: file_get_contents(): Filename cannot be empty

PHP's file_get_contents() function: How to read contents from a file PHP's file_get_contents() function: How to read contents from a file Nov 04, 2023 pm 01:43 PM

PHP's file_get_contents() function: How to read contents from a file

Detailed explanation of PHP file caching functions: file caching processing methods of file_get_contents, file_put_contents, unlink and other functions Detailed explanation of PHP file caching functions: file caching processing methods of file_get_contents, file_put_contents, unlink and other functions Nov 18, 2023 am 09:37 AM

Detailed explanation of PHP file caching functions: file caching processing methods of file_get_contents, file_put_contents, unlink and other functions

PHP function introduction—file_get_contents(): Read the contents of the URL into a string PHP function introduction—file_get_contents(): Read the contents of the URL into a string Jul 24, 2023 pm 02:32 PM

PHP function introduction—file_get_contents(): Read the contents of the URL into a string

How to read file contents using file_get_contents function in PHP How to read file contents using file_get_contents function in PHP Jun 26, 2023 pm 12:01 PM

How to read file contents using file_get_contents function in PHP

Detailed explanation of PHP 5.2 functions: How to use the file_get_contents function to read file contents Detailed explanation of PHP 5.2 functions: How to use the file_get_contents function to read file contents Jul 29, 2023 pm 04:09 PM

Detailed explanation of PHP 5.2 functions: How to use the file_get_contents function to read file contents

PHP function introduction—file_get_contents(): Read file contents into a string PHP function introduction—file_get_contents(): Read file contents into a string Jul 24, 2023 pm 06:40 PM

PHP function introduction—file_get_contents(): Read file contents into a string

See all articles