PHP Classes

File: php/getClientIp.php

Recommend this page to a friend!
  Classes of bamigboye biodun   Logical Functions   php/getClientIp.php   Download  
File: php/getClientIp.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Logical Functions
General-purpose PHP and JavaScript functions
Author: By
Last change:
Date: 1 year ago
Size: 778 bytes
 

Contents

Class file image Download
<?php
function get_client_ip(): string
{
   
$ipaddress = '';
    if (isset(
$_SERVER['HTTP_CLIENT_IP'])) {
       
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    } else if (isset(
$_SERVER['HTTP_X_FORWARDED_FOR'])) {
       
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else if (isset(
$_SERVER['HTTP_X_FORWARDED'])) {
       
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    } else if (isset(
$_SERVER['HTTP_FORWARDED_FOR'])) {
       
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    } else if (isset(
$_SERVER['HTTP_FORWARDED'])) {
       
$ipaddress = $_SERVER['HTTP_FORWARDED'];
    } else if (isset(
$_SERVER['REMOTE_ADDR'])) {
       
$ipaddress = $_SERVER['REMOTE_ADDR'];
    } else {
       
$ipaddress = 'UNKNOWN';
    }

    return
$ipaddress;
}

echo
get_client_ip();