http:// - HTTP(s) URL 액세스

http: // - https: // - HTTP(s) URL에 액세스


설명

HTTP를 통해 파일/리소스에 대한 읽기 전용 액세스를 허용합니다. 기본적으로 HTTP 1.0 GET이 사용됩니다. Host: 헤더는 이름 기반 가상 호스트를 처리하라는 요청과 함께 전송됩니다. php.ini 파일 또는 스트림 컨텍스트를 사용하여 user_agent 문자열을 구성한 경우 요청에도 포함됩니다.

스트림은 리소스 본문에 대한 액세스를 허용합니다. 헤더는 $http_response_header 변수에 저장됩니다.

문서가 제공된 리소스의 URL을 아는 것이 중요한 경우(모든 리디렉션이 처리된 후) 스트림에서 반환된 일련의 응답 헤더를 처리해야 합니다.

from 지시문은 Context 옵션과 매개변수로 덮어쓰지 않고 설정되어 있는 경우 From: 헤더에 사용됩니다.


용법

  • http://example.com
  • http://example.com/file.php?var1=val1&var2=val2
  • http://user:password@example.com
  • https://example.com
  • https://example.com/file.php?var1=val1&var2=val2
  • https://user:password@example.com

옵션

Wrapper Summary

Attribute Supported
Restricted by allow_url_fopen Yes
Allows Reading Yes
Allows Writing No
Allows Appending No
Allows Simultaneous Reading and Writing N/A
Supports stat() No
Supports unlink() No
Supports rename() No
Supports mkdir() No
Supports rmdir() No

Examples

예제 #1 리디렉션 후 어떤 URL에 도달했는지 감지

                  
<?php
$url = 'http://www.example.com/redirecting_page.php';

$fp = fopen($url, 'r');

$meta_data = stream_get_meta_data($fp);
foreach ($meta_data['wrapper_data'] as $response) {

    /* Were we redirected? */
    if (strtolower(substr($response, 0, 10)) == 'location: ') {

        /* update $url with where we were redirected to */
        $url = substr($response, 10);
    }

}

?>
                  
                

노트

참고: HTTPS는 openssl 확장이 활성화된 경우에만 지원됩니다.

HTTP 연결은 읽기 전용입니다. HTTP 리소스에 데이터 쓰기 또는 파일 복사는 지원되지 않습니다.

예를 들어 HTTP 컨텍스트를 사용하여 POST 및 PUT 요청을 보낼 수 있습니다.


기타