$_SERVER['REMOTE_ADDR'] is actually used for getting the IP address from which the user is viewing the current page. But if user is browsing from a company or cafe we will get gateway ip address only. In such situations we can use the following functions
function getUserIP()
{
$ip = "";
if (isset($_SERVER))
{
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} elseif (isset($_SERVER["HTTP_CLIENT_IP"])) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
} else {
$ip = $_SERVER["REMOTE_ADDR"];
}
}
else {
if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
$ip = getenv( 'HTTP_X_FORWARDED_FOR' );
} elseif ( getenv( 'HTTP_CLIENT_IP' ) ) {
$ip = getenv( 'HTTP_CLIENT_IP' );
} else {
$ip = getenv( 'REMOTE_ADDR' );
}
}
return $ip;
}
Blogger templates
Blogger news
Blogroll
Archives
-
▼
2013
(219)
-
▼
June
(18)
- Php Web Development Company Blog with Blog.Co.In
- Create Live Search using Ajax, PHP and Dreamweaver
- simple function in php
- 42 tips for optimizing your php code
- $_POST() in php
- scandir() in php
- Control structures in php: foreach
- Loading...
- Installing of Webserver : Apache 2.0.53
- Google Ads in an AJAX page
- FREE PHP OPTION BR - ,
- Capítulo 18: Networking y FTP usando PHP
- Edit Assignment #2:
- What Is PHP?
- PHP function REMOTE_ADDR is not working
- What is an object in PHP
- Home User's Security Checklist
- Apache won't run after installing XAMPP on Windows 7
-
▼
June
(18)