Find IP Address - Php

How to get the client IP address in Php?

Snippet Code

Rate this page :
  [ 0 votes]

Use this php code to view the real IP address. Here, SERVER["REMOTE_ADDR"] function is used to view the ip address of the client from which the user is viewing the current page.

<?php function getipaddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } echo getipaddr(); ?>


Ask Questions

Ask Question