2

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!

3 Answers 3

5

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) } 
Sign up to request clarification or add additional context in comments.

1 Comment

$_SERVER['SERVER_PROTOCOL'] has it's problems... See stackoverflow.com/q/17640877/632951
2

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

3 Comments

Firstly, thanks for your speedy response, Gumbo. I did actually consider $_SERVER_PROTOCOL, but for some reason I thought the value it returned was what my server used? So, am I now right in thinking that the value of $_SERVER_PROTOCOL corresponds to the requesting user-agent?
@clarky_y2k: Yes, SERVER_PROTOCOL is the protocol that the client used in the current request. Just try an HTTP/1.0 request and see the difference.
@clarky_y2k: variable $_SERVER_PROTOCOL is deprecated in new PHP vresions, use $_SERVER['SERVER_PROTOCOL'] instead it
2

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.