ZCE # Week # 271

Question: 

You run the following PHP Script:

<?php
$value = gethostbyaddr($_SERVER['REMOTE_ADDR']);
echo $value;
?>

What will be the output of the script?

A. It will print the DNS resource records associated with the local Web Server.
B. It will print the standard host name for the local Web Server.
C. It will print the list of header information sent.
D. It will print the host name of the Internet host.

Explanation:

$_SERVER is an array containing information such as headers, paths, and script locations.

  • REMOTE_ADDR -- The IP address from which the user is viewing the current page.
  • REMOTE_HOST -- The host name from which the user is viewing the current page. The reverse dns lookup is based of the REMOTE_ADDR of the user.
  • REMOTE_PORT -- The port being used on the user's machine to communicate with the web server.
  • REMOTE_USER -- The authenticated user.
  • REDIRECT_REMOTE_USER -- The authenticated user if the request is internally redirected.

Related Functions:
  • gethostbyaddr Get the Internet host name corresponding to a given IP address 
  • gethostbyname Get the IPv4 address corresponding to a given Internet host name 
  • gethostbynamel Get a list of IPv4 addresses corresponding to a given Internet host name
  • checkdnsrrCheck DNS records corresponding to a given Internet host name or IP address
  • getmxrrGet MX records corresponding to a given Internet host name
  • dns_get_recordFetch DNS Resource Records associated with a hostname

Predefined variables:

PHP provides a large number of predefined variables to all scripts. The variables represent everything from external variables to built-in environment variables, last error messages to last retrieved headers. 

List of predefined variables of PHP

  • Superglobals -- Superglobals are built-in variables that are always available in all scopes.
  • $GLOBALS -- References all variables in global scope.
  • $_SERVER -- Server and execution environment information.
  • $_GET -- HTTP GET variables.
  • $_POST -- HTTP POST variables.
  • $_FILES -- HTTP File Upload variables.
  • $_SESSION -- Session variables.
  • $_ENV -- Environment variables.
  • $_COOKIE -- HTTP Cookies
  • $php_errormsg -- The previos error message.
  • $HTTP_RAW_POST_DATA -- Raw POST data.
  • $http_response_header -- HTTP response headers.
  • $argc -- The number of arguments passed to script.
  • $argv -- Array of arguments passed to script.
 

Answer:  D