Jordan Clark
Jordan Clark

Reputation: 772

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!

Upvotes: 2

Views: 1102

Answers (3)

You
You

Reputation: 23774

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)
}

Upvotes: 5

Reese Moore
Reese Moore

Reputation: 11640

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

Upvotes: 2

Gumbo
Gumbo

Reputation: 655189

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';

Upvotes: 2

Related Questions