
stream_context_set_options 함수의 첫 번째 인자로 전달하는 context 변수의 타입은 stream_context입니다.
stream_context는 HTTP 요청을 보낼 때 사용하는 옵션을 설정하는 변수입니다.
context 변수에 값을 넣는 방법은 두 가지가 있습니다.
첫 번째 방법은 stream_context_create 함수를 사용하여 stream_context 변수를 생성하고, 그 변수에 옵션을 설정하는 것입니다.
예를 들어, 다음 코드는 stream_context_create 함수를 사용하여 stream_context 변수를 생성하고, 그 변수에 follow_location 옵션을 설정하는 코드입니다.
#hostingforum.kr
php
$opts = array(
'http' => array(
'method' => 'GET',
'follow_location' => 0
)
);
$context = stream_context_create($opts);
두 번째 방법은 stream_context_set_option 함수를 사용하여 stream_context 변수에 옵션을 설정하는 것입니다.
예를 들어, 다음 코드는 stream_context_set_option 함수를 사용하여 follow_location 옵션을 설정하는 코드입니다.
#hostingforum.kr
php
$opts = stream_context_get_options($context);
$opts['http']['follow_location'] = 0;
stream_context_set_options($context, $opts);
context 변수에 값을 넣는 방법은 위의 두 가지 방법 중 하나를 사용하면 됩니다.
context 변수에 값을 넣은 후, stream_context_set_options 함수를 사용하여 옵션을 설정할 수 있습니다.
예를 들어, 다음 코드는 context 변수에 follow_location 옵션을 설정하는 코드입니다.
#hostingforum.kr
php
stream_context_set_options($context, array(
'http' => array(
'follow_location' => 0
)
));
context 변수에 값을 넣은 후, stream_context_set_options 함수를 사용하여 옵션을 설정할 수 있습니다.
stream_context_set_options 함수는 context 변수에 설정된 옵션을 사용하여 HTTP 요청을 보냅니다.
예를 들어, 다음 코드는 stream_context_set_options 함수를 사용하여 HTTP 요청을 보내는 코드입니다.
#hostingforum.kr
php
$opts = array(
'http' => array(
'method' => 'GET',
'follow_location' => 0
)
);
$context = stream_context_create($opts);
$html = file_get_contents('http://example.com', false, $context);
2025-06-29 06:36