Hướng dẫn file_get_contents php returns nothing - file_get_contents php không trả lại gì

-2

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Tôi đang cố gắng để có được nội dung trang web (trả lời JSON) với file_get_contents. Nhưng nó trả về trống var. Cố gắng liên lạc với API Recaptcha của Google. Khi tôi tự mình nhập URL, nó sẽ trả về thông báo JSON tốt, nhưng File_Get_Contents không trả lại gì .. Không có mã nào, vì không có gì phức tạp, chỉ cần File_Get_Contents ("https: // ....") OpenSSL được bật và cho phép quá .s://....") openssl is enabled and allow_url_fopen is enabled too by default.

Mã được thêm vào:

$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$this->settings->captcha_secret_code."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);
$response = json_decode($response, true);

$ Phản hồi trả về 1 và nếu chúng ta nhận xét JSON_DECODING, $ phản hồi = ""

Đã hỏi ngày 13 tháng 11 năm 2017 lúc 20:36Nov 13, 2017 at 20:36

Hướng dẫn file_get_contents php returns nothing - file_get_contents php không trả lại gì

Andrii H.andrii H.Andrii H.

1.5223 huy hiệu vàng15 Huy hiệu bạc39 Huy hiệu đồng3 gold badges15 silver badges39 bronze badges

10

Cố gắng thêm bối cảnh với thông tin SSL:

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>

Đã trả lời ngày 20 tháng 3 năm 2018 lúc 17:30Mar 20, 2018 at 17:30

Hướng dẫn file_get_contents php returns nothing - file_get_contents php không trả lại gì

Vì một số lý do File_Get_Contents không hoạt động với URL của HTTPS. Thay vào đó bạn có thể sử dụng Curl:

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
$response = curl_exec($ch);
curl_close($ch);

$response = json_decode($response, true);

Phức tạp hơn, nhưng nó hoạt động :)

Đã trả lời ngày 13 tháng 11 năm 2017 lúc 21:04Nov 13, 2017 at 21:04

Hướng dẫn file_get_contents php returns nothing - file_get_contents php không trả lại gì

Andrii H.andrii H.Andrii H.

1.5223 huy hiệu vàng15 Huy hiệu bạc39 Huy hiệu đồng3 gold badges15 silver badges39 bronze badges

Ẩn danh ¶

Allenmccabe tại Gmail Dot Com ¶Reads entire file into a string

Sự mô tả

file_get_contents (& nbsp; & nbsp; & nbsp; & nbsp; chuỗi ________ 4, & nbsp; & nbsp; & nbsp; & nbsp; = 0, & nbsp; & nbsp; & nbsp; & nbsp;? Int

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
0 = null): Chuỗi | Sai(
    string $filename,
    bool $use_include_path = false,
    ?resource $context = null,
    int $offset = 0,
    ?int
array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
0 = null

): string|false

file_get_contents () là cách ưa thích để đọc nội dung của tệp thành một chuỗi. Nó sẽ sử dụng các kỹ thuật ánh xạ bộ nhớ nếu được HĐH của bạn hỗ trợ để tăng cường hiệu suất. is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.

Ghi chú::

Nếu bạn đang mở một URI với các ký tự đặc biệt, chẳng hạn như không gian, bạn cần mã hóa URI bằng urlencode ().urlencode().

Thông số

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
2

Tên của tập tin để đọc.

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
3

Ghi chú::

Nếu bạn đang mở một URI với các ký tự đặc biệt, chẳng hạn như không gian, bạn cần mã hóa URI bằng urlencode ().

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
4 constant can be used to trigger include path search. This is not possible if strict typing is enabled, since
array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
4
is an int. Use
array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
6
instead.

Thông số

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
2stream_context_create(). If you don't need to use a custom context, you can skip this parameter by null.

Tên của tập tin để đọc.

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
3

Hằng số

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
4 có thể được sử dụng để kích hoạt bao gồm tìm kiếm đường dẫn. Điều này là không thể nếu gõ nghiêm ngặt được bật, vì
array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
4 là INT. Sử dụng
array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
6 thay thế.

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
7

Một tài nguyên bối cảnh hợp lệ được tạo bằng stream_context_create (). Nếu bạn không cần sử dụng bối cảnh tùy chỉnh, bạn có thể bỏ qua tham số này bằng null.

array( "verify_peer"=>false, "verify_peer_name"=>false, ), ); $context = stream_context_create($opts); $result = file_get_contents( $url , NULL, $context ); echo $result; ?> 9

Phần bù nơi việc đọc bắt đầu trên luồng ban đầu. Độ lệch âm tính từ cuối luồng.false on failure.

Tìm kiếm (

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
9) không được hỗ trợ với các tệp từ xa. Cố gắng tìm kiếm các tệp không phải địa phương có thể hoạt động với các độ lệch nhỏ, nhưng điều này là không thể đoán trước vì nó hoạt động trên luồng được đệm.

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
$response = curl_exec($ch);
curl_close($ch);

$response = json_decode($response, true);
1false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

Errors/Exceptions

Độ dài tối đa của dữ liệu đọc. Mặc định là đọc cho đến khi đạt được kết thúc của tệp. Lưu ý rằng tham số này được áp dụng cho luồng được xử lý bởi các bộ lọc.

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
$response = curl_exec($ch);
curl_close($ch);

$response = json_decode($response, true);
5 level error is generated if
array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
2 cannot be found,
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
$response = curl_exec($ch);
curl_close($ch);

$response = json_decode($response, true);
1 is less than zero, or if seeking to the specified
array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
9 in the stream fails.

Trả về giá trịfile_get_contents() is called on a directory, an

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
$response = curl_exec($ch);
curl_close($ch);

$response = json_decode($response, true);
5 level error is generated on Windows, and as of PHP 7.4 on other operating systems as well.

Hàm trả về dữ liệu đọc hoặc false về lỗi.

Cảnh báoSự mô tả
8.0.0 Hàm này có thể trả về Boolean false, nhưng cũng có thể trả về giá trị phi Boolean đánh giá thành false. Vui lòng đọc phần về Booleans để biết thêm thông tin. Sử dụng toán tử === để kiểm tra giá trị trả về của hàm này.
7.1.0 Lỗi cấp
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
$response = curl_exec($ch);
curl_close($ch);

$response = json_decode($response, true);
5 được tạo ra nếu không thể tìm thấy
array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
2,
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
$response = curl_exec($ch);
curl_close($ch);

$response = json_decode($response, true);
1 nhỏ hơn 0 hoặc nếu tìm kiếm
array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
9 được chỉ định trong luồng không thành công.

Khi file_get_contents () được gọi trên một thư mục, lỗi cấp $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, "YOUR_URL"); $response = curl_exec($ch); curl_close($ch); $response = json_decode($response, true); 5 cũng được tạo trên Windows và kể từ Php 7.4 trên các hệ điều hành khác.

Thay đổi

string(14) "lle Bjori Ro" 
2

Phiên bản

string(14) "lle Bjori Ro" 
3

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
$response = curl_exec($ch);
curl_close($ch);

$response = json_decode($response, true);
1 bây giờ là vô hiệu.

string(14) "lle Bjori Ro" 
4

Hỗ trợ cho

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
9 tiêu cực đã được thêm vào.

string(14) "lle Bjori Ro" 

Ví dụ

string(14) "lle Bjori Ro" 
5

Ví dụ #1 Nhận và xuất nguồn của trang chủ của trang web

Ví dụ #2 Tìm kiếm trong bao gồm_path: This function is binary-safe.

Ví dụ #3 Đọc một phần của tệp

Ví dụ trên sẽ xuất ra một cái gì đó tương tự như:fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.

Tìm kiếm (

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
9) không được hỗ trợ với các tệp từ xa. Cố gắng tìm kiếm các tệp không phải địa phương có thể hoạt động với các độ lệch nhỏ, nhưng điều này là không thể đoán trước vì nó hoạt động trên luồng được đệm.

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
$response = curl_exec($ch);
curl_close($ch);

$response = json_decode($response, true);
1fsockopen() to create an
string(14) "lle Bjori Ro" 
8 socket, the developer is responsible for detecting and suppressing this warning.

Độ dài tối đa của dữ liệu đọc. Mặc định là đọc cho đến khi đạt được kết thúc của tệp. Lưu ý rằng tham số này được áp dụng cho luồng được xử lý bởi các bộ lọc.

  • Trả về giá trị
  • Hàm trả về dữ liệu đọc hoặc false về lỗi.
  • Cảnh báo
  • Hàm này có thể trả về Boolean false, nhưng cũng có thể trả về giá trị phi Boolean đánh giá thành false. Vui lòng đọc phần về Booleans để biết thêm thông tin. Sử dụng toán tử === để kiểm tra giá trị trả về của hàm này.
  • Lỗi cấp
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
    $response = curl_exec($ch);
    curl_close($ch);
    
    $response = json_decode($response, true);
    
    5 được tạo ra nếu không thể tìm thấy
    array(
            "verify_peer"=>false,
            "verify_peer_name"=>false,
        ),
    );
    
    $context = stream_context_create($opts);
    
    $result = file_get_contents( $url , NULL, $context );
    echo $result;
    
    ?>
    
    2,
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
    $response = curl_exec($ch);
    curl_close($ch);
    
    $response = json_decode($response, true);
    
    1 nhỏ hơn 0 hoặc nếu tìm kiếm
    array(
            "verify_peer"=>false,
            "verify_peer_name"=>false,
        ),
    );
    
    $context = stream_context_create($opts);
    
    $result = file_get_contents( $url , NULL, $context );
    echo $result;
    
    ?>
    
    9 được chỉ định trong luồng không thành công.
  • Khi file_get_contents () được gọi trên một thư mục, lỗi cấp
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
    $response = curl_exec($ch);
    curl_close($ch);
    
    $response = json_decode($response, true);
    
    5 cũng được tạo trên Windows và kể từ Php 7.4 trên các hệ điều hành khác.
  • Thay đổi
  • $http_response_header

Phiên bản

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "YOUR_URL");
$response = curl_exec($ch);
curl_close($ch);

$response = json_decode($response, true);
1 bây giờ là vô hiệu.

string(14) "lle Bjori Ro" 
9

$filename0

$filename1

$filename2

Hỗ trợ cho

array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

$context = stream_context_create($opts);

$result = file_get_contents( $url , NULL, $context );
echo $result;

?>
9 tiêu cực đã được thêm vào.

Ví dụ

$filename3

$filename4

$filename5

$filename6

Ví dụ #1 Nhận và xuất nguồn của trang chủ của trang web

Ví dụ #2 Tìm kiếm trong bao gồm_path

$filename7

Ví dụ #3 Đọc một phần của tệp

Ví dụ #2 Tìm kiếm trong bao gồm_path

$filename8

Ví dụ #3 Đọc một phần của tệp

Ví dụ #2 Tìm kiếm trong bao gồm_path

$filename9

$use_include_path0

$use_include_path1