Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Exploring $_SERVER | PHP Superglobals
Quizzes & Challenges
Quizzes
Challenges
/
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

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 2

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

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

Svep för att visa menyn

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

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 2
some-alt