Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Exploring $_SERVER | PHP Superglobals
PHP Core Concepts

bookExploring $_SERVER

The $_SERVER superglobal is an array in PHP that contains information about headers, paths, and script locations. It is populated by the web server and provides useful details about the current request and server environment. Some of the most common keys you will use include:

server_info.php

server_info.php

copy
12345678910111213141516
<?php // Print server name echo "Server Name: " . $_SERVER['SERVER_NAME'] . "<br>"; // Print request method echo "Request Method: " . $_SERVER['REQUEST_METHOD'] . "<br>"; // Print script name echo "Script Name: " . $_SERVER['SCRIPT_NAME'] . "<br>"; // Print server software echo "Server Software: " . $_SERVER['SERVER_SOFTWARE'] . "<br>"; // Print HTTP host echo "HTTP Host: " . $_SERVER['HTTP_HOST'] . "<br>"; ?>
SERVER_NAME
expand arrow

The name of the server host under which the current script is executing.

REQUEST_METHOD
expand arrow

The request method used to access the page, such as GET or POST.

SCRIPT_NAME
expand arrow

The path of the current script relative to the document root.

SERVER_SOFTWARE
expand arrow

The web server identification string, like "Apache/2.4.41 (Unix)".

HTTP_HOST
expand arrow

The host header from the current request.

These keys are especially useful for debugging, logging, and building dynamic applications that need to adapt to different server environments or respond to specific requests. For example, you might use REQUEST_METHOD to check if a form was submitted via POST, or use SCRIPT_NAME to generate links relative to the current script.

question mark

Which $_SERVER key would you use to get the current script's filename?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 2

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you list some of the most commonly used $_SERVER keys?

How can I use $_SERVER to check the request method in PHP?

Can you give an example of using $_SERVER for debugging?

bookExploring $_SERVER

Свайпніть щоб показати меню

The $_SERVER superglobal is an array in PHP that contains information about headers, paths, and script locations. It is populated by the web server and provides useful details about the current request and server environment. Some of the most common keys you will use include:

server_info.php

server_info.php

copy
12345678910111213141516
<?php // Print server name echo "Server Name: " . $_SERVER['SERVER_NAME'] . "<br>"; // Print request method echo "Request Method: " . $_SERVER['REQUEST_METHOD'] . "<br>"; // Print script name echo "Script Name: " . $_SERVER['SCRIPT_NAME'] . "<br>"; // Print server software echo "Server Software: " . $_SERVER['SERVER_SOFTWARE'] . "<br>"; // Print HTTP host echo "HTTP Host: " . $_SERVER['HTTP_HOST'] . "<br>"; ?>
SERVER_NAME
expand arrow

The name of the server host under which the current script is executing.

REQUEST_METHOD
expand arrow

The request method used to access the page, such as GET or POST.

SCRIPT_NAME
expand arrow

The path of the current script relative to the document root.

SERVER_SOFTWARE
expand arrow

The web server identification string, like "Apache/2.4.41 (Unix)".

HTTP_HOST
expand arrow

The host header from the current request.

These keys are especially useful for debugging, logging, and building dynamic applications that need to adapt to different server environments or respond to specific requests. For example, you might use REQUEST_METHOD to check if a form was submitted via POST, or use SCRIPT_NAME to generate links relative to the current script.

question mark

Which $_SERVER key would you use to get the current script's filename?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 2
some-alt