0
0
PHPprogramming~20 mins

$_SERVER information in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
$_SERVER Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of accessing $_SERVER['REQUEST_METHOD']?
Consider a PHP script accessed via a POST request. What will echo $_SERVER['REQUEST_METHOD']; output?
PHP
<?php
// Assume this script is accessed via POST method
echo $_SERVER['REQUEST_METHOD'];
?>
APOST
BGET
CPUT
DDELETE
Attempts:
2 left
💡 Hint
Think about how the HTTP method used to access the page is stored in $_SERVER.
Predict Output
intermediate
2:00remaining
What does $_SERVER['HTTP_USER_AGENT'] contain?
If you run echo $_SERVER['HTTP_USER_AGENT']; in a PHP script, what kind of information will it output?
PHP
<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>
AThe browser and operating system details of the client
BThe server software version
CThe requested URL path
DThe IP address of the client
Attempts:
2 left
💡 Hint
User agent strings describe the client software making the request.
🧠 Conceptual
advanced
2:00remaining
Which $_SERVER key gives the absolute path of the currently executing script?
You want to get the full filesystem path to the PHP script currently running. Which $_SERVER key should you use?
A'REQUEST_URI'
B'PHP_SELF'
C'SCRIPT_FILENAME'
D'DOCUMENT_ROOT'
Attempts:
2 left
💡 Hint
Think about the difference between URL paths and filesystem paths.
Predict Output
advanced
2:00remaining
What error occurs when accessing an undefined $_SERVER key?
What happens if you try to echo $_SERVER['NON_EXISTENT_KEY'] in PHP?
PHP
<?php
echo $_SERVER['NON_EXISTENT_KEY'];
?>
AThrows a fatal error and stops script execution
BOutputs an empty string with a PHP Notice about undefined index
COutputs the string 'NON_EXISTENT_KEY'
DOutputs NULL silently without any error
Attempts:
2 left
💡 Hint
PHP warns about undefined array keys but does not stop execution by default.
🧠 Conceptual
expert
3:00remaining
How to securely get the client's IP address using $_SERVER?
Which $_SERVER key is the most reliable and secure to get the client's real IP address in PHP?
A'SERVER_ADDR'
B'HTTP_X_FORWARDED_FOR'
C'HTTP_CLIENT_IP'
D'REMOTE_ADDR'
Attempts:
2 left
💡 Hint
Some keys can be spoofed by the client or proxies.