How to Detect the Server Protocol for PHP
You can use PHP to extract details of a server's protocol so that you can enable code specific to the server's version. A common use is to detect if the page is running standard HTTP or secure HTTPS. Information about the server's protocol is stored in the superglobal variable array "$_SERVER," which you can access anywhere in your script.
Instructions
-
-
1
Open your PHP source file in a text editor, such as Windows Notepad.
-
2
Use "$_SERVER['SERVER_NAME'];" to access the name of the server host that PHP is running. For example, "echo $_SERVER['SERVER_NAME'];" may display a string such as "www.myserver.com."
-
-
3
Use "$_SERVER['SERVER_SOFTWARE'];" to access the server identification string, which appears in headers. For example, "echo $_SERVER['SERVER_SOFTWARE'];" may display a string such as "Apache/2.2.3 (CentOS)."
-
4
Use "$_SERVER['SERVER_PROTOCOL'];" to access the revision and name of the information protocol used for the requested page. For example, "echo $_SERVER['SERVER_PROTOCOL'];" may display a string such as "HTTP/1.1."
-
5
Save the PHP file and load it on your server to make sure it works properly.
-
1
Tips & Warnings
PHP code must be contained within "<?php" and "?>" tags.
Depending on the server, "$_SERVER" may not provide meaningful values for many of its indices, especially if PHP is run from the command line.