Complete the code to print the current script's filename using the $_SERVER superglobal.
<?php
echo $_SERVER[[1]];
?>The $_SERVER['SCRIPT_NAME'] contains the path of the current script.
Complete the code to get the client's IP address from the $_SERVER array.
<?php
$ip = $_SERVER[[1]];
echo $ip;
?>The $_SERVER['REMOTE_ADDR'] contains the IP address of the client accessing the script.
Fix the error in the code to correctly print the request method used by the client.
<?php
echo $_SERVER[[1]];
?>The correct key to get the HTTP request method is 'REQUEST_METHOD'.
Fill both blanks to create an associative array with the client's browser info and the server's software.
<?php $info = [ 'browser' => $_SERVER[[1]], 'server' => $_SERVER[[2]] ]; print_r($info); ?>
$_SERVER['HTTP_USER_AGENT'] gives the client's browser info, and $_SERVER['SERVER_SOFTWARE'] gives the server software details.
Fill all three blanks to create a dictionary comprehension that maps each key in $_SERVER to its length if the length is greater than 10.
<?php
$lengths = array_filter(array_map(function($k) {
return strlen($k);
}, array_keys($_SERVER)), function($len) {
return $len [1] 10;
});
$result = [];
foreach ($_SERVER as [2] => [3]) {
if (strlen([2]) > 10) {
$result[[2]] = strlen([2]);
}
}
print_r($result);
?>The comparison operator should be '>' to check length greater than 10. The foreach loop uses $key and $value as variable names for keys and values.