On Tue, 20 Nov 2001 11:38, Ben Clumeck wrote: > Thanks for your response David. I am new to PHP. Are you saying that > the code would look like this: > <? > gethostname for $IPADDR; > if $HOSTNAME = $IPADDR > print "$HOSTNAME" > ?> > Would I then put the $HOSTNAME into my mail() script. Sorry for the > trouble. > > Ben > > -----Original Message----- > From: David Robley [mailto:[EMAIL PROTECTED]] > Sent: Monday, November 19, 2001 4:29 PM > To: Ben Clumeck; [EMAIL PROTECTED] > Subject: Re: [PHP] IP Address Converted to Computer Name > > On Tue, 20 Nov 2001 04:08, Ben Clumeck wrote: > > I am trying to convert an ip address to a computer name. Then I am > > putting it into the mail() script. However, when I do this it come > > up blank. I am putting $r_hostname in the mail() script. Can anyone > > tell me why its not working? The script I am using is: > > <? > > $r_hostname = gethostbyaddr($REMOTE_ADDR); > > if ($REMOTE_ADDR == "$r_hostname"); > > echo "$r_hostname"; > > ?> > > > > Thanks, > > > > Ben > > Remember that not all IP adrresses will resolve to a hostname. That > said, there may be a flaw in your logic in the code snippet above :-) > > What you are saying is: > > gethostname for IPADDR; > if HOSTNAME = IPADDR > print HOSTNAME > > which will only work if the resolved hostname is the same as the IP > address; I suspect that is not what you want?
When you reply, can you put your response at the bottom? Makes it ieasier to read the chronological story. Yes, I know Outhouse puts you at the top - another 'feature' from MS. No, I am not saying the code should look like that; what I wrote is pseudocode that just tells what the flow of logic is. To put it simply, you are only asking for $r_hostname to be echoed, in that particular code snippet, if the value in $r_hostname is the same as the IP address. And I notice there is a syntax error or three in your snippet. Now I guess that what you want to do is to add the remote hostname to the email only if it resolves and you get back a hostname rather than an IP address? If that is the case, then you want something like: <? $r_hostname = gethostbyaddr($REMOTE_ADDR); if ($REMOTE_ADDR != "$r_hostname") { echo "$r_hostname"; } ?> Note the curly brackets around the contents of the IF. If you substitute the IP addresses 129.96.218.127 and 129.96.218.27 for $REMOTE_ADDR you'll see the first returns a hostname and the second returns just the IP address, so the first will print a hostname and the second won't. -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA NEWS! Stolen painting found by tree -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]