Zend Certified PHP Engineer (ZCPE) Practice Test

Question: 1 / 400

How can you retrieve the IP address of a user in PHP?

Using $_GET['ip']

Using $_SERVER['REMOTE_ADDR']

To retrieve the IP address of a user in PHP, utilizing the `$_SERVER['REMOTE_ADDR']` superglobal is the correct approach. This variable contains the IP address from which the user is viewing the current page. It captures the address provided by the web server and is the standard method for obtaining client IP information in PHP.

This method is reliable because `$_SERVER['REMOTE_ADDR']` is set by the server environment during the user's request and reflects the direct connection point. It works effectively in most scenarios, including when running on standard shared hosting environments.

Other choices, while they refer to ways data might be accessed in PHP, do not accurately capture the user's IP address. For instance, the `$_GET`, `$_POST`, and `$_COOKIE` arrays are used for capturing data sent to the server via URL parameters, form submissions, or cookie data, respectively, but they do not represent the user's IP address directly. Thus, they are not suitable for this specific requirement.

Get further explanation with Examzify DeepDiveBeta

Using $_COOKIE['ip']

Using $_POST['ip']

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy