Topic: Displaye your real ip
<?php
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
echo 'Your IP is: '.$ip; ?>
What do youse think?
We are a group of graphic designers and web developers trying to create a social network for the people, and not for the commercialization of said social network.
You are not logged in. Please login or register.
Index → Code The World → PHP Snippets → Displaye your real ip
<?php
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
echo 'Your IP is: '.$ip; ?>
What do youse think?
Cool...
$_SERVER['HTTP_X_FORWARDED_FOR'] is proxy behind the NAT router. And it could contain multiple IP addresses if the request was forwarded trough multiple proxies. So, maybe convert it to an array, something like this:
$ip = array();
// check if it's set, and if it's more then one
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && strpos($_SERVER['HTTP_X_FORWARDED_FOR'],','))
{
$ip += explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']); //add IPs from all proxies to the ip array
} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip[] = $_SERVER['HTTP_X_FORWARDED_FOR']; // add the one that you got
}
$ip[] = $_SERVER['REMOTE_ADDR']; // the default one
Index → Code The World → PHP Snippets → Displaye your real ip
Powered by PunBB, supported by Informer Technologies, Inc.
Currently used extensions: pun_admin_manage_extensions_improved, pun_poll, pun_quote, pun_bbcode, pun_repository, pun_tags, pun_admin_add_user, google_analytics, pun_eggdrop, pun_recaptcha.
Copyright © 2007 - 2025 CodeTheWorld
Generated in 0.008 seconds (63% PHP - 37% DB) with 8 queries