Passed
Push — 1.0.0-dev ( b68981...00dab9 )
by nguereza
05:23
created

get_ip()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 4
eloc 15
c 3
b 0
f 0
nc 6
nop 0
dl 0
loc 21
rs 9.7666
1
<?php
2
	defined('ROOT_PATH') || exit('Access denied');
3
	/**
4
	 * TNH Framework
5
	 *
6
	 * A simple PHP framework using HMVC architecture
7
	 *
8
	 * This content is released under the GNU GPL License (GPL)
9
	 *
10
	 * Copyright (C) 2017 Tony NGUEREZA
11
	 *
12
	 * This program is free software; you can redistribute it and/or
13
	 * modify it under the terms of the GNU General Public License
14
	 * as published by the Free Software Foundation; either version 3
15
	 * of the License, or (at your option) any later version.
16
	 *
17
	 * This program is distributed in the hope that it will be useful,
18
	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
	 * GNU General Public License for more details.
21
	 *
22
	 * You should have received a copy of the GNU General Public License
23
	 * along with this program; if not, write to the Free Software
24
	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
	*/
26
27
28
	/**
29
	 *  @file function_user_agent.php
30
	 *    
31
	 *  Contains most of the utility functions for agent, platform, mobile, browser, and other management.
32
	 *  
33
	 *  @package	core
34
	 *  @author	Tony NGUEREZA
35
	 *  @copyright	Copyright (c) 2017
36
	 *  @license	https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL)
37
	 *  @link	http://www.iacademy.cf
38
	 *  @version 1.0.0
39
	 *  @since 1.0.0
40
	 *  @filesource
41
	 */
42
	
43
	 
44
	if(! function_exists('get_ip')){
45
		/**
46
		 *  Retrieves the user's IP address
47
		 *  
48
		 *  This function allows to retrieve the IP address of the client
49
		 *  even if it uses a proxy, the actual IP address is retrieved.
50
		 *  
51
		 *  @return string the IP address.
52
		 */
53
		function get_ip(){
54
			$ip = '127.0.0.1';
55
			$ipServerVars = array(
56
								'REMOTE_ADDR',
57
								'HTTP_CLIENT_IP',
58
								'HTTP_X_FORWARDED_FOR',
59
								'HTTP_X_FORWARDED',
60
								'HTTP_FORWARDED_FOR',
61
								'HTTP_FORWARDED'
62
							);
63
			foreach ($ipServerVars as $var) {
64
				if(isset($_SERVER[$var])){
65
					$ip = $_SERVER[$var];
66
					break;
67
				}
68
			}
69
			// Strip any secondary IP etc from the IP address
70
			if (strpos($ip, ',') > 0) {
71
				$ip = substr($ip, 0, strpos($ip, ','));
72
			}
73
			return $ip;
74
		}
75
	}
76