라이브러리

[PHP] Yaf_Response_Abstract::setHeader - 응답 헤더 설정




PHP Yaf_Response_Abstract::setHeader


Yaf_Response_Abstract::setHeader는 PHP의 Yaf 프레임워크에서 사용할 수 있는 메소드입니다. 이 메소드는 HTTP 헤더를 설정하는 데 사용됩니다.

# 사용법


Yaf_Response_Abstract::setHeader 메소드는 두 개의 파라미터를 받습니다. 첫 번째 파라미터는 헤더 이름, 두 번째 파라미터는 헤더 값입니다.

#hostingforum.kr
php

$response = new Yaf_Response_Abstract();

$response->setHeader('Content-Type', 'text/html; charset=UTF-8');



# 예제


다음 예제는 Yaf_Response_Abstract::setHeader 메소드를 사용하여 HTTP 헤더를 설정하는 방법을 보여줍니다.

#hostingforum.kr
php

// Yaf_Response_Abstract::setHeader 예제

$response = new Yaf_Response_Abstract();



// Content-Type 헤더 설정

$response->setHeader('Content-Type', 'text/html; charset=UTF-8');



// Cache-Control 헤더 설정

$response->setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');



// Expires 헤더 설정

$response->setHeader('Expires', '0');



// Last-Modified 헤더 설정

$response->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');



// Content-Length 헤더 설정

$response->setHeader('Content-Length', strlen('Hello, World!'));



// 헤더 출력

foreach ($response->getHeaders() as $header) {

    echo $header . "
";

}



# 결과


이 예제의 결과는 다음과 같습니다.

#hostingforum.kr


Content-Type: text/html; charset=UTF-8

Cache-Control: no-cache, no-store, must-revalidate

Expires: 0

Last-Modified: Wed, 01 Jan 2020 00:00:00 GMT

Content-Length: 13



# 참고


Yaf_Response_Abstract::setHeader 메소드는 HTTP 헤더를 설정하는 데 사용됩니다. 이 메소드는 Yaf 프레임워크에서 사용할 수 있는 메소드 중 하나입니다. 헤더를 설정하는 방법을 보여주는 예제를 포함했습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 16 페이지

검색

게시물 검색