Jump to content

Archived

This topic is now archived and is closed to further replies.

koolgirl

help gethostbyaddr($_SERVER['REMOTE_ADDR'])

Recommended Posts

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

Share this post


Link to post
Share on other sites
Try this:
[code]<?php
$sql = "INSERT INTO Records SET IP='" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "'";
?>[/code]

Ken

Share this post


Link to post
Share on other sites
-Alternative Syntax-

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

Share this post


Link to post
Share on other sites
No, using the "Set" is an alternative syntax for INSERT. It works fine. I use it all the time.

Ken

Share this post


Link to post
Share on other sites
Heh, my bad. I like this forum because you always learn something :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.