Home >Backend Development >PHP Tutorial >PHP uses static classes to implement the method of obtaining the client IP address

PHP uses static classes to implement the method of obtaining the client IP address

WBOY
WBOYOriginal
2016-07-25 09:03:121013browse
  1. /**

  2. * Miscellaneous utility methods.
  3. */
  4. final class Utils {

  5. private function __construct() {

  6. }
  7. /**

  8. * Get IP address
  9. * @return string IP address string
  10. */
  11. public static function getIpAddress() {
  12. return $_SERVER["REMOTE_ADDR"];
  13. }
  14. }
  15. ?>

Copy the code

2. Call

  1. $last_login_ip = Utils::getIpAddress();
  2. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn