'phP 기초 다지기/HTTP 헤더'에 해당되는 글 2건

php에서는 보통 Media Type 헤더를 다음과 같이 사용합니다.

 Accept: */*
 Accept: type/*
 Accept: type/subtype

subtype Media Type 헤더목록은 다음과 같습니다.

 text/enricbed
 text/btml
 text/plain
 text/sgml
 text/tab-separated-values
 text/xml
 text/x-setext
 text/html

 multipart/alternative
 multipart/appledouble
 multipart/digest
 multipart/form-data
 multipart/beader-set
 multipart/mixed
 multipart/parallel
 multipart/related
 multipart/report
 multipart/voice-message

 model/iges
 model/mesb
 model/vnd.dwf
 model/vrml

 image/cgm
 image/g3fax
 image/gif
 image/ief
 image/jpeg
 image/naplps
 image/png
 image/tiff
 image/vnd.dwg
 image/vnd.dxf
 image/vnd.fpx
 image/vnd.net-fpx
 image/vnd.svf
 image/vnd.xiff
 image/x-cmu-raster
 image/x-portable-anymap
 image/x-portable-bitmap
 image/x-portable-graymap
 image/x-portable-pixmap
 image/x-rgb
 image/x-xbitmap
 image/x-xpixmap
 image/x-xwindowdump
 image/external-body
 image/bttp
 image/news
 image/partial
 image/rfc822

 audio/32kadpcm
 audio/32kadpcm
 audio/basic
 audio/vnd.qcelp
 audio/x-aiff
 audio/x-wav

 application/activemessage
 application/andrew-inset
 application/applefile
 application/atomicmail
 application/cals-1840
 application/commonground
 application/cybercasb
 application/dca-rft
 application/dec-dx
 application/EDI-Consent
 application/EDIFACT
 application/EDI-X12
 application/esbop
 application/byperstudio
 application/iges
 application/mac-binbex40
 application/macwriteii
 application/marc
 application/matbematica
 application/msword
 application/news-message-id
 application/news-transmission
 application/octet-stream
 application/oda
 application/pdf
 application/pgp-encrypted
 application/pgp-keys
 application/pkcs7-mime
 application/pkcs7-signature
 application/pkcs10
 application/postscript
 application/prs.alvestrand.titrax-sbeet
 application/prs.cww
 application/prs.nprend
 application/remote-printing
 application/riscos
 application/rtf
 application/set-payment-initiation
 application/set-payment
 application/set-registration-initiation
 application/set-registration
 application/sgml
 application/sgml-open-catalog
 application/slate
 application/vemmi
 application/vnd.$commerce_battelle
 application/vnd.3M.Post-it-Notes
 application/vnd.acucobol
 application/vnd.anser-web-funds-transfer-initiation
 application/vnd.audiograpb
 application/vnd.businessobjects
 application/vnd.claymore
 application/vnd.comsocaller
 application/vnd.dna
 application/vnd.dxr
 application/vnd.ecdis-update
 application/vnd-ecowin-cbart
 application/vnd.ecowin.filerequest
 application/vnd.ecowin.fileupdate
 application/vnd.ecowin.series
 application/vnd.ecowin.seriesrequest
 application/vnd.ecowin.seriesupdate
 application/vnd.enliven
 application/vnd.epson.salt
 application/vnd.fdf
 application/vnd.ffsns
 application/vnd.FloGrapblt
 application/vnd.framemaker
 application/vnd.fujitsu.oasys
 application/vnd.fujitsu.oasys2
 application/vnd.fujitsu.oasys3
 application/vnd.fujitsu.oasysprs
 application/vnd.fusitsu.oasysgp
 application/vnd.fjixerox.docuworks
 application/vnd.bp-bps
 application/vnd.bp-HPGL
 application/vnd.bp-PCL
 application/vnd.bp-PCLXL
 application/vnd.ibm.MiniPay
 application/vnd.ibm.modcap
 application/vnd.intercon.formnet
 application/vnd.intertrust.digibox
 application/vnd.intertrust.nncp
 application/vnd.is-xpr
 application/vnd.japannet-directory-service
 application/vnd.japannet-jpnstore-wakeup
 application/vnd.japannet-japayment-wakeup
 application/vnd.japannet-registration
 application/vnd.japannet-registration-wakeup
 application/vnd.japannet-setstore-wakeup
 application/vnd.japannet-verification
 application/vnd.japannet-verification-wakeup
 application/vnd.koan
 application/vnd.lotus-wordpro
 application/vnd.lotus-approacb
 application/vnd.lotus-1-2-3
 application/vnd.lotus-organizer
 application/vnd.lotus-screencam
 application/vnd.lotus-freelance
 application/vnd.meridian-slingsbot
 application/vnd.mif
 application/vnd.minisoft-bp3000-save
 application/vnd.mitsubisbi.misty-guard.trustweb
 application/vnd.ms-artgalry
 application/vnd.ms-asf
 application/vnd.ms-excel
 application/vnd.ms-powerpoint
 application/vnd.ms-project
 application/vnd.ms-tnef
 application/vnd.ms-works
 application/vnd.music-niff
 application/vnd.musician
 application/vnd.netfpx
 application/vnd.noblenet-web
 application/vnd.noblenet-sealer
 application/vnd.noblenet-directory
 application/vnd.novadigm.EDM
 application/vnd.novadigm.EDX
 application/vnd.novadign.EXT
 application/vnd.osa.netdeploy
 application/vnd.powerbuilder6
 application/vnd.powerbuilder6-s
 application/vnd.rapid
 application/vnd.seemail
 application/vnd.sbana.informed.formtemplate
 application/vnd.sbana.informed.form-data
 application/vnd.sbana.informed.package
 application/vnd.sbana.informed.inter-cbange
 application/vnd.street-stream
 application/vnd.svd
 application/vnd.swiftview-ics
 application/vnd.truedoc
 application/vnd.visio
 application/vnd.webturbo
 application/vnd.wrq-bp3000-labelled
 application/vnd.wt.stf
 application/vnd.xara
 application/vnd.yellowriver-custom-menu
 application/wita
 application/wordpefect5.1
 application/x-bcpio
 application/x-cpio
 application/x-csb
 application/x-dvi
 application/x-gtar
 application/x-bdf
 application/x-latex
 application/x-mif
 application/x-netcdf
 application/x-sb
 application/x-sbar
 application/x-sv4cpio
 application/x-sv4crc
 application/x-tar
 application/x-tcl
 application/x-tex
 application/x-texinfo
 application/x-troff-man
 application/x-troff-ms
 application/x-troff-me
 application/x-troff
 application/x-ustar
 application/x-wais-source
 application/xml
 application/x400-bp
 application/zip
블로그 이미지

하보니

하보니와 함께하는 phP 초보

댓글을 달아 주세요

모든 헤더 정보는 자동으로 $http_response_header 변수에 저장되며, 이로 HTTP 응답 헤더정보를 볼 수 있게 되었습니다. gmail에 접속하면 다음과 같은 응답을 받게 됩니다.

예제 (ex #1
 <?php
 file_get_contents
("http://gmail.com"
);
 
print_r($http_response_header
);

 
/*
 결과:
 Array
 (
    [0] => HTTP/1.0 301 Moved Permanently
    [1] => Location: http://mail.google.com/mail/
    [2] => Content-Type: text/html; charset=UTF-8
    [3] => X-Content-Type-Options: nosniff
    [4] => Date: Wed, 04 May 2011 17:58:11 GMT
    [5] => Expires: Fri, 03 Jun 2011 17:58:11 GMT
    [6] => Server: sffe
    [7] => Content-Length: 225
    [8] => X-XSS-Protection: 1; mode=block
    [9] => Cache-Control: public, max-age=2592000
    [10] => Age: 52305
    [11] => HTTP/1.0 302 Moved Temporarily
    [12] => Content-Type: text/html; charset=UTF-8
    [13] => Cache-Control: no-cache, no-store, max-age=0, must-revalidate
    [14] => Pragma: no-cache
    [15] => Expires: Fri, 01 Jan 1990 00:00:00 GMT
    [16] => Date: Thu, 05 May 2011 08:29:56 GMT
    [17] => Location: https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=llya694le36z&scc=1&ltmpl=default&ltmplcache=2
    [18] => Content-Length: 408
    [19] => X-Content-Type-Options: nosniff
    [20] => X-Frame-Options: SAMEORIGIN
    [21] => X-XSS-Protection: 1; mode=block
    [22] => Server: GSE
 )
 */
 
?>

다음은 habony.tistory.com에 응답 헤더를 보겠습니다.

예제 (ex #2
 <?php
 file_get_contents
("http://habony.tistory.com"
);
 
print_r($http_response_header
);

 
/*
 결과:
 Array
 (
    [0] => HTTP/1.1 200 OK
    [1] => Date: Thu, 05 May 2011 08:27:25 GMT
    [2] => Server: Apache
    [3] => Set-Cookie: TSSESSION=7c3acd117e518c4b; path=/; domain=tistory.com
    [4] => Expires: Thu, 19 Nov 1981 08:52:00 GMT
    [5] => Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    [6] => Pragma: no-cache
    [7] => Set-Cookie: visited_new=1304584045; expires=Thu, 05-May-2011 15:00:00 GMT; path=/; domain=habony.tistory.com
    [8] => Connection: close
    [9] => Content-Type: text/html; charset=utf-8
 )
 */
 
?>

array get_headers ( string $url [, int $format= 0 ] ) (PHP 5)

get_headers
함수로도 이와 같은 비슷한 기능을 흉내낼 수 있습니다. format인자로 정돈된 데이터를 받게 됩니다.

예제 (ex #3

 <?php
 $data 
get_headers("http://daum.net"1
)
 
print_r($data
);

 
/*
 결과:
 Array
 (
    [0] => HTTP/1.1 302 Object Moved
    [Location] => http://www.daum.net/
    [Content-Type] => Array (
            [0] => text/html
            [1] => text/html; charset=utf-8
    )
    [Cache-Control] => Array (
            [0] => private
            [1] => no-cache, no-store, must-revalidate
    )
    [Connection] => Array (
            [0] => close
            [1] => close
    )
    [1] => HTTP/1.1 200 OK
    [Date] => Thu, 05 May 2011 08:46:07 GMT
    [Server] => Apache
    [Expires] => Sat, 01, Jan 1970 22:00:00 GMT
    [Pragma] => no-cache
    [P3P] => CP="ALL DSP COR MON LAW IVDi HIS IVAi DELi SAMi
 OUR LEG PHY UNI ONL DEM ST
 A INT NAV PUR FIN OTC GOV" [Set-Cookie] => dtck_seq=0; path=/; expires=Sat, 04-Jun-2011 08:46:07 GMT; domain=www.daum.net [Vary] => Accept-Encoding
 )
 */
 
?> 

블로그 이미지

하보니

하보니와 함께하는 phP 초보

댓글을 달아 주세요