PDA

View Full Version : show ip #


teamwasabi
05-12-2001, 07:46 AM
How do I show the peoples IP# when they first enter my page?

Like 'Hello ###.##.##.#'

Gerry
05-13-2001, 12:54 AM
The easiest thing would be to use Server Side Includes (SSI). You'd have to name the page with a ".shtml" file extension (or set up .htaccess to parse all ".html" pages), but all you would need to add to your page with SSI is:

Hello, <!--#echo var="REMOTE_ADDR " -->

RevKev
05-13-2001, 01:23 AM
Don't you love choices on how to do something? I think the following php code should do the same thing, as well:

<?
$ipa = getenv ("REMOTE_ADDR")
echo "Hello, $ipa \n";
?>

RevKev
05-13-2001, 07:29 AM
I'm just learning php, myself, so this is probably QUITE oversimplified... But...

Basically, by making your page webpage.php instead of webpage.html, you can include php code. You can use all the same html code as before, but now you can include php code along with it. the <? ?> tags show when php code starts <? and when it stops ?>. In other words, put the php code in between them.

So a VERY SIMPLE page that would do nothing but show a users IP address might look like:

<html>
<head>
<title>Your IP Address</title>
</head>

<body>

<?
$ipa = getenv ("REMOTE_ADDR")
echo "Hello, $ipa \n";
?>

</body>

</html>


The first line of the above php (the stuff between the <? and ?>) uses the function "getenv" to get the IP address and sets it as the value for the variable "$ipa" (a name I made up). The next line displays "Hello, (value of the variable)"

Of course, the little php code can be placed anywhere within the rest of the html code, which makes it nice to work with.

It does seem "too easy", mostly because this really is a pretty simple use of php. Then again, from what I've seen, php is really pretty simple to use. Until about a week ago, I had never even heard of php. 3 days ago, I bought a book on it and have been reading up on the discussions about it in these forums.

I don't consider myself a programmer, and I'm not ready to write major programs like vBulletin, but I have set up a rather easy to use form mail script and am working on adding password protected user access to the rather plain chat room offered through the control panel (so people login with a registered screen name).

So, anyway, with apologies for the verbosity, just give it a try. Good luck!

petesmc
05-13-2001, 08:12 AM
Her is my SSI article:

http://www.codingclick.com/article.php/aid/2

Gerry
05-13-2001, 01:44 PM
Yep, SSI is often the quickest means of doing a simple display of available server variables.

If I were going to do this with a perl CGi script, I'd go one step further while I was at it and run an nslookup of the IP address so I could also display the domain name:

# Get visitor's IP addr and domain name
$ip = $ENV{'REMOTE_ADDR'};
$n = `/usr/bin/nslookup -q=A $ip | grep Name:`; chop($n);
$host=substr($n, rindex($n, " ")+1);
if ($host eq "") { $host=$ENV{'REMOTE_ADDR'}; }

# Start main processing routine
MAIN:
{

# Print out a Content-Type for HTTP/1.0 compatibility
print "Content-Type: text/html\n\n";

print <<"EndPrint";
<html>
<head>
<title>IP Info</title>
</head>
<body>
<div align="center">
<h1>IP Info</h1>
visitor's IP address is:
<br>&nbsp;<br>
<strong>$ip</strong>
<br>&nbsp;<br>
nslookup of $ip gives:
<br>&nbsp;<br>
<strong>$host</strong>
</div>
</body>
</html>
EndPrint

exit 0;
}

RevKev
05-14-2001, 01:05 AM
I'm using "PHP and MySQL Web Development" by Luke Welling and Laura Thomson, published by SAMS, ISBN: 0-672-31784-2

petesmc
05-14-2001, 01:45 PM
Hi,

There is a few more I think , but most are not used at all.

I'll try to update my article some time.

-Peter