开发者

How do I detect what version of HTTP a user-agent supports, using PHP?

Sorry if this question seems a little basic for some of you, but my programming knowledge leaves a lot to be desired, to say the least!

What I would like to know is this: When a request is made to my web server, how do I detect the version of HTTP that the requesting user-agent supports (i.e. HTTP/1.0 or HTTP/1.1)? The server-side scripting language that my server uses is PHP version 5.2.

Basically, I would like to use PHP to do something like this:

if(/* user agent is currently using HTTP/1.1 */) {
 // do 开发者_运维百科this...
}
else {
 // do something else...
}

I would be very grateful if somebody could point me in the right direction. Thanks in advance!


The superglobal $_SERVER variable generally contains this kind of information. In this case, you're interested in the SERVER_PROTOCOL entry:

if($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1'){
    // Client is using HTTP/1.1
} else {
    // Client is using a different protocol (likely HTTP/1.0)
}


You can use $_SERVER['SERVER_PROTOCOL']:

'SERVER_PROTOCOL'
Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0';


$_SERVER['SERVER_PROTOCOL'] will have the version of HTTP by which the page was requested. link.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜