1The simplest way to collect the Client/Visitor IP address using PHP is the REMOTE_ADDR.
2Pass the 'REMOTE_ADDR' in PHP $_SERVER variable. It will return the IP address of the visitor who is currently viewing the webpage.
3
4Get the IP address of the website
5<?php
6echo 'User IP Address : '. $_SERVER['REMOTE_ADDR'];
7?>
8
9/*
10I Hope it will help you.
11Namaste
12Stay Home Stay Safe
13*/
1function getIp() {
2 $ip = $_SERVER['REMOTE_ADDR'];
3
4 if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
5 $ip = $_SERVER['HTTP_CLIENT_IP'];
6 } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
7 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
8 }
9
10 return $ip;
11}
1#to best handle proxies use this:
2if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
3 $ip = $_SERVER['HTTP_CLIENT_IP'];
4} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
5 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
6} else {
7 $ip = $_SERVER['REMOTE_ADDR'];
8}