?
Solved

Display/log host name only

Posted on 2003-03-25
3
Medium Priority
?
247 Views
Last Modified: 2006-11-17
<?
$ip = $REMOTE_ADDR;
$host = gethostbyaddr($ip);
?>

This will return the user's IP address and Host in a single line. If I wish to solely display the Host and still be able to return each value individually how would I go about that? In short I still want to be able to log the user's IP address, but only display the Host name.


0
Comment
Question by:getWise
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
Kriek earned 300 total points
ID: 8203947
<?php
    $ip = $_SERVER['REMOTE_ADDR'];
    $fullhost = gethostbyaddr($ip);
    $host = preg_replace("/^[^.]+./", "*.", $fullhost);
?>

IP address: <?=$ip?> | Host: <?=$host?>

Using your example aside from assigning a superglobal to a variable. You can still log the IP address of your visitors and only show the hostname or show them both.




0
 

Author Comment

by:getWise
ID: 8203965
Thanks Kriek! That is exactly what I was looking for. Although I am not familiar with the slang superglobal could you point me in the right direction as far as manual references, perhaps?
0
 
LVL 1

Expert Comment

by:Kriek
ID: 8204003
You could classify superglobal arrays (4.1.0) under ..

Predefined variables: http://www.php.net/manual/en/language.variables.predefined.php 

I suppose, but $_SERVER is also considered a ..

Reserved predefined variable: http://www.php.net/manual/en/reserved.variables.php 

I started using superglobals just after PHP 4.2.0 was released. (External variables are no longer registered in the global scope by default, register_globals off by default)
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question