Introduction:
Explore the power of PHP with the $_SERVER superglobal! In this comprehensive lesson, we delve into the essential server-side variables that PHP provides for handling server and client information. Whether you’re a beginner or an experienced developer, understanding $_SERVER is crucial for building dynamic and interactive web applications.
In PHP, $_SERVER is a superglobal array that provides information about the server environment and the current request. It contains information such as headers, paths, and script locations.
Here are some commonly used elements within the $_SERVER array:
Returns the filename of the currently executing script, relative to the document root.
$current_script = $_SERVER[‘PHP_SELF’];
Returns the name of the server host under which the current script is executing.
$server_name = $_SERVER[‘SERVER_NAME’];
Returns the agent string (browser information) from the current request.
$_agent = $_SERVER[‘HTTP__AGENT’];
Returns the IP address of the client making the request.
$client_ip = $_SERVER[‘REMOTE_ADDR’];
Returns the request method used by the current request (e.g., ‘GET’, ‘POST’, ‘PUT’, etc.).
$request_method = $_SERVER[‘REQUEST_METHOD’];
Returns the query string, if any, via which the page was accessed.
$query_string = $_SERVER[‘QUERY_STRING’];
Returns the URL of the page that referred the current request.
$referer = $_SERVER[‘HTTP_REFERER’];
Returns the Host header from the current request.
$host = $_SERVER[‘HTTP_HOST’];
Returns the URI (Uniform Resource Identifier) that was given in order to access this page. It includes the query string.
$request_uri = $_SERVER[‘REQUEST_URI’];
Returns the path of the current script.
$script_name = $_SERVER[‘SCRIPT_NAME’];
Returns the port on the server machine being used by the web server for communication. Common values are 80 for HTTP and 443 for HTTPS.
$server_port = $_SERVER[‘SERVER_PORT’];
Returns a string indicating if the script is being run on a secure server. It is either an empty string or “on”.
$is_https = isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] === ‘on’;
Returns the root directory of the server document.
$document_root = $_SERVER[‘DOCUMENT_ROOT’];
Returns the preferred language of the , based on the browser settings.
$accept_language = $_SERVER[‘HTTP_ACCEPT_LANGUAGE’];
Returns the raw HTTP cookies sent with the request.
$raw_cookies = $_SERVER[‘HTTP_COOKIE’];
Returns the name and version of the web server software.
$server_software = $_SERVER[‘SERVER_SOFTWARE’];
Returns the timestamp of the start time of the request.
$request_time = $_SERVER[‘REQUEST_TIME’];
Returns the Accept header from the current request, indicating the MIME types that the client can handle.
$accept_header = $_SERVER[‘HTTP_ACCEPT’];
Returns the hostname of the client making the request, if available.
$remote_host = $_SERVER[‘REMOTE_HOST’];
Returns the IP address of the server.
$server_ip = $_SERVER[‘SERVER_ADDR’];
Returns the name and revision of the information protocol (such as “HTTP/1.1”).
$protocol = $_SERVER[‘SERVER_PROTOCOL’];
Returns the absolute pathname of the currently executing script.
$script_filename = $_SERVER[‘SCRIPT_FILENAME’];
Returns the URL-path for the current request, excluding any query string.
$redirect_url = $_SERVER[‘REDIRECT_URL’];
Returns the HTTP response status for the request, if it has been internally redirected.
$redirect_status = $_SERVER[‘REDIRECT_STATUS’];
Returns the version of the Common Gateway Interface (CGI) the server is using.
$gateway_interface = $_SERVER[‘GATEWAY_INTERFACE’];
Returns the value given to the server administrator’s email address.
$server_admin = $_SERVER[‘SERVER_ADMIN’];
Returns a server-specific string that is added to server-generated documents.
$server_signature = $_SERVER[‘SERVER_SIGNATURE’];
Returns the Connection header from the current request.
$connection_header = $_SERVER[‘HTTP_CONNECTION’];
Returns the Host header from the current request.
$host_header = $_SERVER[‘HTTP_HOST’];
Returns the URI of the current script.
$script_uri = $_SERVER[‘SCRIPT_URI’];
Returns the URL of the current script.
$script_url = $_SERVER[‘SCRIPT_URL’];
Returns a server-specific signature or banner that is included in server-generated documents.
$server_signature = $_SERVER[‘SERVER_SIGNATURE’];
Returns any path information that follows the actual script filename but does not include the query string.
$path_info = $_SERVER[‘PATH_INFO’];
Returns a non-empty value if the request was made through the HTTPS protocol.
$is_https = isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] !== ‘off’;
Returns the value of the X-Requested-With header, which is often used to identify AJAX requests.
$requested_with = isset($_SERVER[‘HTTP_X_REQUESTED_WITH’]) ? strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) : ”;
$is_ajax = $requested_with === ‘xmlhttprequest’;
Returns the request scheme (http or https).
$request_scheme = $_SERVER[‘REQUEST_SCHEME’];
Returns the port of the client machine that is connected to the web server.
$remote_port = $_SERVER[‘REMOTE_PORT’];
Returns the name and revision of the information protocol (e.g., “HTTP/1.1”).
$server_protocol = $_SERVER[‘SERVER_PROTOCOL’];
Returns the original URI requested by the client.
$document_uri = $_SERVER[‘DOCUMENT_URI’];
Returns the group ID of the running the script.
$script_group = $_SERVER[‘SCRIPT_GROUP’];
complete examples in html with explanation
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>PHP $_SERVER Example</title> </head> <body> <h1>PHP $_SERVER Example</h1> <?php // Example 1: Display the current script file $current_script = htmlspecialchars($_SERVER['PHP_SELF']); echo "<p>Current Script: $current_script</p>"; // Example 2: Display the server name $server_name = htmlspecialchars($_SERVER['SERVER_NAME']); echo "<p>Server Name: $server_name</p>"; // Example 3: Display the agent $_agent = htmlspecialchars($_SERVER['HTTP__AGENT']); echo "<p> Agent: $_agent</p>"; // Example 4: Display the client's IP address $client_ip = htmlspecialchars($_SERVER['REMOTE_ADDR']); echo "<p>Client IP Address: $client_ip</p>"; // Example 5: Display the request method $request_method = htmlspecialchars($_SERVER['REQUEST_METHOD']); echo "<p>Request Method: $request_method</p>"; // Example 6: Display the query string $query_string = htmlspecialchars($_SERVER['QUERY_STRING']); echo "<p>Query String: $query_string</p>"; ?> </body> </html>
Explanation:
DOCTYPE and HTML Structure: The HTML document starts with the <!DOCTYPE html> declaration and the basic HTML structure.
PHP Section: Inside the <body> tag, PHP code is embedded between <?php and ?>. In this section, various $_SERVER variables are accessed and displayed.
HTML Display: Each example is wrapped in an HTML <p> (paragraph) element, displaying the result of the corresponding $_SERVER variable.
The htmlspecialchars function is used to prevent potential security issues by escaping HTML entities.
To view this example, save the code above into a file with a .php extension (e.g., server_example.php) and open it in a web browser via a local or remote server environment with PHP support.
The page will display information about the server environment and the current request.
Examples
Let’s continue with examples using various $_SERVER variables. This time, we’ll focus on additional elements to showcase their usage.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title> PHP $_SERVER Examples</title> </head> <body> <h1> PHP $_SERVER Examples</h1> <?php // Example 7: Display the server port $server_port = htmlspecialchars($_SERVER['SERVER_PORT']); echo "<p>Server Port: $server_port</p>"; // Example 8: Check if the request is secure (HTTPS) $is_https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'; echo "<p>Is HTTPS: " . ($is_https ? 'Yes' : 'No') . "</p>"; // Example 9: Display the accept language from the request $accept_language = htmlspecialchars($_SERVER['HTTP_ACCEPT_LANGUAGE']); echo "<p>Accept Language: $accept_language</p>"; // Example 10: Display the raw HTTP cookies $raw_cookies = htmlspecialchars($_SERVER['HTTP_COOKIE']); echo "<p>Raw Cookies: $raw_cookies</p>"; // Example 11: Display the server software information $server_software = htmlspecialchars($_SERVER['SERVER_SOFTWARE']); echo "<p>Server Software: $server_software</p>"; // Example 12: Display the server administrator's email $server_admin = htmlspecialchars($_SERVER['SERVER_ADMIN']); echo "<p>Server Administrator: $server_admin</p>"; // Example 13: Display the server's IP address $server_ip = htmlspecialchars($_SERVER['SERVER_ADDR']); echo "<p>Server IP Address: $server_ip</p>"; ?> </body> </html>
Explanation:
Example 7 – Server Port: Displays the server port used for communication, often 80 for HTTP and 443 for HTTPS.
Example 8 – Is HTTPS: Checks if the request is made through the HTTPS protocol.
Example 9 – Accept Language: Displays the preferred language of the based on the browser settings.
Example 10 – Raw Cookies: Displays the raw HTTP cookies sent with the request.
Example 11 – Server Software: Displays the name and version of the web server software.
Example 12 – Server Administrator: Displays the value given to the server administrator’s email address.
Example 13 – Server IP Address: Displays the IP address of the server.
Save this code in a PHP file and view it in a web browser to see the output of these additional $_SERVER examples. Adjustments can be made based on your server environment and specific needs.
Example
Let’s continue with examples using various $_SERVER variables. This time, we’ll cover additional elements to showcase their usage.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Even PHP $_SERVER Examples</title> </head> <body> <h1>Even PHP $_SERVER Examples</h1> <?php // Example 14: Display the path of the current script $script_path = htmlspecialchars($_SERVER['SCRIPT_NAME']); echo "<p>Script Path: $script_path</p>"; // Example 15: Display the absolute pathname of the currently executing script $script_filename = htmlspecialchars($_SERVER['SCRIPT_FILENAME']); echo "<p>Script Filename: $script_filename</p>"; // Example 16: Display the document root of the server $document_root = htmlspecialchars($_SERVER['DOCUMENT_ROOT']); echo "<p>Document Root: $document_root</p>"; // Example 17: Display the protocol used in the request (http or https) $request_scheme = htmlspecialchars($_SERVER['REQUEST_SCHEME']); echo "<p>Request Scheme: $request_scheme</p>"; // Example 18: Display the port of the client machine $remote_port = htmlspecialchars($_SERVER['REMOTE_PORT']); echo "<p>Remote Port: $remote_port</p>"; // Example 19: Display the protocol and version (e.g., "HTTP/1.1") $server_protocol = htmlspecialchars($_SERVER['SERVER_PROTOCOL']); echo "<p>Server Protocol: $server_protocol</p>"; // Example 20: Display the original URI requested by the client $document_uri = htmlspecialchars($_SERVER['DOCUMENT_URI']); echo "<p>Document URI: $document_uri</p>"; // Example 21: Display the group ID of the running the script $script_group = htmlspecialchars($_SERVER['SCRIPT_GROUP']); echo "<p>Script Group ID: $script_group</p>"; ?> </body> </html>
Explanation:
Example 14 – Script Path: Displays the path of the current script relative to the document root.
Example 15 – Script Filename: Displays the absolute pathname of the currently executing script.
Example 16 – Document Root: Displays the document root of the server.
Example 17 – Request Scheme: Displays the protocol used in the request (http or https).
Example 18 – Remote Port: Displays the port of the client machine connected to the web server.
Example 19 – Server Protocol: Displays the name and revision of the information protocol (e.g., “HTTP/1.1”).
Example 20 – Document URI: Displays the original URI requested by the client.
Example 21 – Script Group ID: Displays the group ID of the running the script.
Save this code in a PHP file and view it in a web browser to see the output of these additional $_SERVER examples. As always, adjust the code based on your server environment and specific requirements.
Example
Here are examples using various $_SERVER variables to showcase their usage:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Advanced PHP $_SERVER Examples</title> </head> <body> <h1>Advanced PHP $_SERVER Examples</h1> <?php // Example 22: Display the URI path without the query string $path_info = htmlspecialchars($_SERVER['PATH_INFO']); echo "<p>Path Info: $path_info</p>"; // Example 23: Check if the request is an AJAX request $requested_with = isset($_SERVER['HTTP_X_REQUESTED_WITH']) ? strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) : ''; $is_ajax = $requested_with === 'xmlhttprequest'; echo "<p>Is AJAX Request: " . ($is_ajax ? 'Yes' : 'No') . "</p>"; // Example 24: Display the connection type from the request $connection_type = htmlspecialchars($_SERVER['HTTP_CONNECTION']); echo "<p>Connection Type: $connection_type</p>"; // Example 25: Display the server signature or banner $server_signature = htmlspecialchars($_SERVER['SERVER_SIGNATURE']); echo "<p>Server Signature: $server_signature</p>"; // Example 26: Display the accept header from the request $accept_header = htmlspecialchars($_SERVER['HTTP_ACCEPT']); echo "<p>Accept Header: $accept_header</p>"; // Example 27: Display the original URL of the page that referred the request $referer = htmlspecialchars($_SERVER['HTTP_REFERER']); echo "<p>Referer: $referer</p>"; // Example 28: Display the server group ID $server_group = htmlspecialchars($_SERVER['SERVER_GROUP']); echo "<p>Server Group ID: $server_group</p>"; // Example 29: Display the server's protocol and host $server_protocol_and_host = htmlspecialchars($_SERVER['SERVER_PROTOCOL']) . '://' . htmlspecialchars($_SERVER['HTTP_HOST']); echo "<p>Server Protocol and Host: $server_protocol_and_host</p>"; ?> </body> </html>
Explanation:
Example 22 – Path Info: Displays any path information that follows the actual script filename but does not include the query string.
Example 23 – Is AJAX Request: Checks if the request is an AJAX request by inspecting the X-Requested-With header.
Example 24 – Connection Type: Displays the Connection header from the current request.
Example 25 – Server Signature: Displays a server-specific signature or banner that is included in server-generated documents.
Example 26 – Accept Header: Displays the Accept header from the current request, indicating the MIME types that the client can handle.
Example 27 – Referer: Displays the URL of the page that referred the current request.
Example 28 – Server Group ID: Displays the group ID of the running the server.
Example 29 – Server Protocol and Host: Displays the combination of server protocol and host.
Save this code in a PHP file and view it in a web browser to see the output of these additional $_SERVER examples. Adjustments can be made based on your server environment and specific needs.
Examples
Here are examples using various $_SERVER variables to showcase their usage:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Advanced PHP $_SERVER Examples</title> </head> <body> <h1>Advanced PHP $_SERVER Examples</h1> <?php // Example 30: Display the server's admin email from the request $server_admin_email = htmlspecialchars($_SERVER['SERVER_ADMIN']); echo "<p>Server Admin Email: $server_admin_email</p>"; // Example 31: Display the server's signature (banner) with HTML tags $server_signature_html = $_SERVER['SERVER_SIGNATURE']; echo "<p>Server Signature (HTML): $server_signature_html</p>"; // Example 32: Display the server's software information with HTML tags $server_software_html = $_SERVER['SERVER_SOFTWARE']; echo "<p>Server Software (HTML): $server_software_html</p>"; // Example 33: Display the server's IP address and port $server_ip_and_port = htmlspecialchars($_SERVER['SERVER_ADDR']) . ':' . htmlspecialchars($_SERVER['SERVER_PORT']); echo "<p>Server IP and Port: $server_ip_and_port</p>"; // Example 34: Display the server's group name $server_group_name = htmlspecialchars($_SERVER['SERVER_NAME']); echo "<p>Server Group Name: $server_group_name</p>"; // Example 35: Display the server's request time $request_time = htmlspecialchars($_SERVER['REQUEST_TIME']); echo "<p>Request Time: " . date('Y-m-d H:i:s', $request_time) . "</p>"; // Example 36: Display the server's request scheme $request_scheme = htmlspecialchars($_SERVER['REQUEST_SCHEME']); echo "<p>Request Scheme: $request_scheme</p>"; // Example 37: Display the server's protocol, host, and script name $server_info = htmlspecialchars($_SERVER['SERVER_PROTOCOL']) . '://' . htmlspecialchars($_SERVER['HTTP_HOST']) . htmlspecialchars($_SERVER['SCRIPT_NAME']); echo "<p>Server Info: $server_info</p>"; ?> </body> </html>
Explanation:
Example 30 – Server Admin Email: Displays the server administrator’s email address.
Example 31 – Server Signature (HTML): Displays the server-specific signature (banner) with HTML tags.
Example 32 – Server Software (HTML): Displays the server software information with HTML tags.
Example 33 – Server IP and Port: Displays the server’s IP address and port.
Example 34 – Server Group Name: Displays the server group name.
Example 35 – Request Time: Displays the timestamp of the start time of the request formatted as a date and time.
Example 36 – Request Scheme: Displays the request scheme (http or https).
Example 37 – Server Info: Displays the combination of server protocol, host, and script name.
Save this code in a PHP file and view it in a web browser to see the output of these additional $_SERVER examples. Adjustments can be made based on your server environment and specific needs.
Example
Here are examples using various $_SERVER variables to showcase their usage:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Advanced PHP $_SERVER Examples</title> </head> <body> <h1>Advanced PHP $_SERVER Examples</h1> <?php // Example 38: Display the server's response status $response_status = htmlspecialchars($_SERVER['REDIRECT_STATUS']); echo "<p>Response Status: $response_status</p>"; // Example 39: Display the server's group name $server_group = htmlspecialchars($_SERVER['SERVER_GROUP']); echo "<p>Server Group: $server_group</p>"; // Example 40: Display the script's group name $script_group = htmlspecialchars($_SERVER['SCRIPT_GROUP']); echo "<p>Script Group: $script_group</p>"; // Example 41: Display the server's software information with HTML tags $server_signature_html = $_SERVER['SERVER_SIGNATURE']; echo "<p>Server Signature (HTML): $server_signature_html</p>"; // Example 42: Display the connection type from the request $connection_type = htmlspecialchars($_SERVER['HTTP_CONNECTION']); echo "<p>Connection Type: $connection_type</p>"; // Example 43: Display the server's admin email from the request $server_admin_email = htmlspecialchars($_SERVER['SERVER_ADMIN']); echo "<p>Server Admin Email: $server_admin_email</p>"; // Example 44: Display the original URL of the page that referred the request $referer = htmlspecialchars($_SERVER['HTTP_REFERER']); echo "<p>Referer: $referer</p>"; // Example 45: Display the path of the current script without the script name $directory = pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME); echo "<p>Directory of Current Script: $directory</p>"; ?> </body> </html>
Explanation:
Example 38 – Response Status: Displays the HTTP response status for the request.
Example 39 – Server Group: Displays the group name of the server.
Example 40 – Script Group: Displays the group name of the script.
Example 41 – Server Signature (HTML): Displays the server-specific signature (banner) with HTML tags.
Example 42 – Connection Type: Displays the Connection header from the current request.
Example 43 – Server Admin Email: Displays the server administrator’s email address.
Example 44 – Referer: Displays the URL of the page that referred the current request.
Example 45 – Directory of Current Script: Displays the directory of the current script without the script name.
Save this code in a PHP file and view it in a web browser to see the output of these additional $_SERVER examples. Adjustments can be made based on your server environment and specific needs.
Example
Here are a few examples using various $_SERVER variables to showcase their usage:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title> PHP $_SERVER Examples</title> </head> <body> <h1> PHP $_SERVER Examples</h1> <?php // Example 46: Display the HTTP accept encoding header $accept_encoding = htmlspecialchars($_SERVER['HTTP_ACCEPT_ENCODING']); echo "<p>Accept Encoding: $accept_encoding</p>"; // Example 47: Display the server's process ID $process_id = htmlspecialchars($_SERVER['SERVER_PID']); echo "<p>Server Process ID: $process_id</p>"; // Example 48: Display the server's thread ID $thread_id = htmlspecialchars($_SERVER['SERVER_TID']); echo "<p>Server Thread ID: $thread_id</p>"; // Example 49: Display the server's process group ID $process_group_id = htmlspecialchars($_SERVER['SERVER_GID']); echo "<p>Server Process Group ID: $process_group_id</p>"; // Example 50: Display the server's thread group ID $thread_group_id = htmlspecialchars($_SERVER['SERVER_TGROUP']); echo "<p>Server Thread Group ID: $thread_group_id</p>"; // Example 51: Display the server's architecture $architecture = htmlspecialchars($_SERVER['SERVER_ARCH']); echo "<p>Server Architecture: $architecture</p>"; // Example 52: Display the server's platform $platform = htmlspecialchars($_SERVER['SERVER_PLATFORM']); echo "<p>Server Platform: $platform</p>"; // Example 53: Display the server's protocol version $protocol_version = htmlspecialchars($_SERVER['SERVER_PROTOCOL_VERSION']); echo "<p>Server Protocol Version: $protocol_version</p>"; ?> </body> </html>
Explanation:
Example 46 – Accept Encoding: Displays the HTTP accept encoding header, indicating the encoding algorithms that the client can understand.
Example 47 – Server Process ID: Displays the process ID of the server.
Example 48 – Server Thread ID: Displays the thread ID of the server.
Example 49 – Server Process Group ID: Displays the process group ID of the server.
Example 50 – Server Thread Group ID: Displays the thread group ID of the server.
Example 51 – Server Architecture: Displays the architecture of the server.
Example 52 – Server Platform: Displays the platform of the server.
Example 53 – Server Protocol Version: Displays the protocol version of the server.
Save this code in a PHP file and view it in a web browser to see the output of these additional $_SERVER examples. Adjustments can be made based on your server environment and specific needs.
Example
Here are examples using various $_SERVER variables:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title> PHP $_SERVER Examples</title> </head> <body> <h1> PHP $_SERVER Examples</h1> <?php // Example 54: Display the server's memory limit for scripts $memory_limit = ini_get('memory_limit'); echo "<p>Memory Limit: $memory_limit</p>"; // Example 55: Display the server's upload max file size limit $max_file_size = ini_get('upload_max_filesize'); echo "<p>Upload Max File Size: $max_file_size</p>"; // Example 56: Display the server's maximum execution time for scripts $max_execution_time = ini_get('max_execution_time'); echo "<p>Max Execution Time: $max_execution_time seconds</p>"; // Example 57: Display the server's date and time $server_time = date('Y-m-d H:i:s'); echo "<p>Server Time: $server_time</p>"; // Example 58: Display the server's timezone $server_timezone = date_default_timezone_get(); echo "<p>Server Timezone: $server_timezone</p>"; // Example 59: Display the server's supported compression methods $compression_methods = htmlspecialchars($_SERVER['HTTP_ACCEPT_ENCODING']); echo "<p>Supported Compression Methods: $compression_methods</p>"; // Example 60: Display the server's software information with HTML tags $server_software_html = htmlspecialchars($_SERVER['SERVER_SOFTWARE']); echo "<p>Server Software (HTML): $server_software_html</p>"; // Example 61: Display the client's language preference $client_language = htmlspecialchars($_SERVER['HTTP_ACCEPT_LANGUAGE']); echo "<p>Client Language: $client_language</p>"; ?> </body> </html>
Explanation:
Example 54 – Memory Limit: Displays the server’s memory limit for scripts.
Example 55 – Upload Max File Size: Displays the server’s maximum upload file size limit.
Example 56 – Max Execution Time: Displays the server’s maximum execution time for scripts.
Example 57 – Server Time: Displays the server’s date and time.
Example 58 – Server Timezone: Displays the server’s timezone.
Example 59 – Supported Compression Methods: Displays the compression methods supported by the client.
Example 60 – Server Software (HTML): Displays the server software information with HTML tags.
Example 61 – Client Language: Displays the client’s language preference.
Save this code in a PHP file and view it in a web browser to see the output of these additional $_SERVER examples. Adjustments can be made based on your server environment and specific needs.
a) The server’s IP address
b) The client’s agent
c) The request method used to access the script
d) The server’s software information
a) if ($_SERVER[‘HTTPS’] == ‘secure’)
b) if ($_SERVER[‘IS_HTTPS’] == true)
c) if (isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] !== ‘off’)
d) if ($_SERVER[‘PROTOCOL’] == ‘https’)
a) $_SERVER[‘HTTP_ACCEPT_LANGUAGE’]
b) $_SERVER[‘_LANGUAGE’]
c) $_SERVER[‘PREFERRED_LANG’]
d) $_SERVER[‘BROWSER_LANG’]
a) The server’s root directory
b) The path of the current script
c) The original URI requested by the client
d) The client’s IP address
a) $_SERVER[‘SERVER_IP’]
b) $_SERVER[‘HOST_IP’]
c) $_SERVER[‘SERVER_ADDR’]
d) $_SERVER[‘IP_ADDRESS’]
1-c) The request method used to access the script
2-c) if (isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] !== ‘off’)
3-a) $_SERVER[‘HTTP_ACCEPT_LANGUAGE’]
4-b) The path of the current script
5-c) $_SERVER[‘SERVER_ADDR’]
a) The server’s IP address
b) The name and version of the web server software
c) The client’s browser information
d) The path of the current script
a) $_SERVER[‘REQUEST_URI’]
b) $_SERVER[‘SCRIPT_URI’]
c) $_SERVER[‘URI’]
d) $_SERVER[‘ORIGINAL_URI’]
a) $_SERVER[‘REQUEST_TIME’]
b) $_SERVER[‘TIME_STAMP’]
c) $_SERVER[‘REQUEST_START’]
d) $_SERVER[‘START_TIME’]
a) It contains the client’s IP address.
b) It provides information about the agent.
c) It indicates the server’s protocol and host.
d) It contains the URL of the page that referred the request.
a) if ($_SERVER[‘IS_AJAX’] == true)
b) if ($_SERVER[‘AJAX’] == ‘request’)
c) if (isset($_SERVER[‘HTTP_X_REQUESTED_WITH’]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) === ‘xmlhttprequest’)
d) if ($_SERVER[‘REQUEST_METHOD’] == ‘AJAX’)
Answers:
6. b) The name and version of the web server software
7-a) $_SERVER[‘REQUEST_URI’]
8-a) $_SERVER[‘REQUEST_TIME’]
9-d) It contains the URL of the page that referred the request.
10-c) if (isset($_SERVER[‘HTTP_X_REQUESTED_WITH’]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) === ‘xmlhttprequest’)
a) The server’s IP address
b) The absolute pathname of the currently executing script
c) The document root of the server
d) The original URI requested by the client
a) $_SERVER[‘PROTOCOL’]
b) $_SERVER[‘REQUEST_PROTOCOL’]
c) $_SERVER[‘HTTPS’]
d) $_SERVER[‘SERVER_PROTOCOL’]
a) The server’s agent
b) The client’s agent
c) The client’s IP address
d) The server’s software information
a) $_SERVER[‘ROOT_PATH’]
b) $_SERVER[‘DOCUMENT_ROOT’]
c) $_SERVER[‘SERVER_PATH’]
d) $_SERVER[‘ROOT_DIRECTORY’]
a) The server’s IP address
b) The client’s IP address
c) The server’s administrator email
d) The server’s thread ID
11. b) The absolute pathname of the currently executing script
12-c) $_SERVER[‘HTTPS’]
13-b) The client’s agent
14-b) $_SERVER[‘DOCUMENT_ROOT’]
15-b) The client’s IP address