Help - Search - Members - Calendar
Full Version: Telling Someones Ip
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Project-Paradox
To define someone's IP We have to use the PHP REMOTE_ADDR Superglobal like this,
CODE
<?php $ip=$_SERVER['REMOTE_ADDR']  ?>


But if we want to tell someone's ip we have to do this;

CODE
<b>IP Address= <?php $ip ?></b>


If you just want to have the full thing in PHP we will use this,

CODE
<?php $ip=$_SERVER['REMOTE_ADDR'];
echo "<b>IP Address= $ip</b>";  ?>

Live Priview
Have Fun, P.S Is there a tutorial section? o.O
Adam
Amazing, just amazing.
Thanks.
Alex
You should use $_SERVER['REMOTE_ADDR'] not $REMOTE_ADDR.
$_SERVER['REMOTE_ADDR'] is part of a superglobal, not a function.

http://uk2.php.net/manual/en/reserved.vari...ariables.server <-- better resource than this tutorial.
Project-Paradox
QUOTE(Alex @ Sep 24 2007, 07:21 PM) *
You should use $_SERVER['REMOTE_ADDR'] not $REMOTE_ADDR.
$_SERVER['REMOTE_ADDR'] is part of a superglobal, not a function.

http://uk2.php.net/manual/en/reserved.vari...ariables.server <-- better resource than this tutorial.

I'll Change it to the superglobal, and i don't use php.net that often,
SP_
This blew my mind. Incredible.
MrTouz
im impressed... really, powerfull in 2 lines of code tongue.gif
Zytran
http://www.php.net/getenv
Enom
You could just have used:
CODE
<?php echo $_SERVER['REMOTE_ADDR']; ?>


To display user's IP even with proxy:
CODE
<?php
$ip="";
$ip_proxy="";
if (getenv(HTTP_X_FORWARDED_FOR))
{
   if (getenv(HTTP_CLIENT_IP))
      $ip=getenv(HTTP_CLIENT_IP);
   else
   {
      $ip=getenv(HTTP_X_FORWARDED_FOR);
      $ip_proxy=getenv(REMOTE_ADDR);
   }
}
else
   $ip=getenv(REMOTE_ADDR);
echo $ip;
?>


Alex - removed shorttags, portability is a concern in public forum posts.
Mark
QUOTE(Project-Paradox @ Sep 24 2007, 02:22 PM) *
i don't use php.net that often,

I suggest you start using it more. It's probably the best resource for writing scripts/programs in PHP.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.