Jump to content


Photo

help gethostbyaddr($_SERVER['REMOTE_ADDR'])


  • Please log in to reply
4 replies to this topic

#1 koolgirl

koolgirl
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 05 June 2006 - 10:23 PM

Hi

got tired trying to solve this problem. I have been using the following script to store visitor's data. It is working fine:

<?php

$dbcnx = @mysql_connect(

'mysql','username','mypass');

mysql_select_db("Main");

$sql = "INSERT INTO Records SET " .

"IP='$REMOTE_ADDR', " .

"BrowserName='$HTTP_USER_AGENT', " .

"Language='$HTTP_ACCEPT_LANGUAGE', " .

"Referer='$HTTP_REFERER', " .

"Date=NOW()";

***********************************************

I want to store the user's host name also. I know this will display the host name on screen:

<?
echo "Your Host Name: " . gethostbyaddr($_SERVER['REMOTE_ADDR'])";

?>

************************************************

but the problem is how to store it in database? it returns error if I write it this way:

<?php

$dbcnx = @mysql_connect(

'mysql','username','mypass');

mysql_select_db("Main");

$sql = "INSERT INTO Records SET " .

"IP=gethostbyaddr($_SERVER['REMOTE_ADDR'])";

******************************************


All help would be very much appriciated. Many Thanks

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 05 June 2006 - 11:27 PM

Try this:
<?php
$sql = "INSERT INTO Records SET IP='" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "'";
?>

Ken

#3 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 06 June 2006 - 02:57 AM

-Alternative Syntax-

<?php
$sql = "INSERT INTO `records` (IP) VALUES ('" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "')";
?>

~ D Kuang

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 06 June 2006 - 03:18 AM

No, using the "Set" is an alternative syntax for INSERT. It works fine. I use it all the time.

Ken

#5 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 06 June 2006 - 03:25 AM

Heh, my bad. I like this forum because you always learn something :)
~ D Kuang




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users