...

View Full Version : IP Logging with Name?



martynball
09-03-2008, 04:09 PM
Hi, I was wondering if there was anyway to log someone IP Address into a database using MySQL, and put the users name next to that IP address.

You could get the name of the visitor by asking them to input their name into a popup alert box, which will then say "Welcome back "Their Name" every time they visit the website. So it will save a cookie.

Please could someone make me a script for this? Please.

Philip M
09-03-2008, 04:35 PM
Client-side Javascript cannot capture a user's IP address.
You need a server-side language such as PHP to do that.

Have a look at:-

http://www.debilsoft.de/us/index.php


We have created a window of opportunity and it is time to walk through that window - Sports commentator.

ess
09-03-2008, 07:40 PM
Philip M,

I think you will find that JS is more than capable of capturing user's IP address. In fact, it can be used to scan a local network etc.

here is an example of you can do this


var userIp = new java.net.InetAddress.getLocalHost();
document.write(userIp.toString().substring(userIp.toString().indexOf("/")+1));

Although you might need to have JVM installed in order to achieve this...I think you will find that most users these days have JVM installed on their machines

As for storing IP addresses into a database, you will need a scripting or programming language capable of communicating with databases.

Of course, you can utilize AJAX, but you will still need a scripting language running on a local or remote server.

Cheers
~E

Philip M
09-03-2008, 08:02 PM
JVM = Java Virtual Machine

Java != Javascript


As for storing IP addresses into a database, you will need a scripting or programming language capable of communicating with databases.

Yes, that it what I tried to convey.


<?
//"ip.php" example- display user IP address on any page
Header("content-type: application/x-javascript");
$serverIP=$_SERVER['REMOTE_ADDR'];
echo "document.write(\"<center><font face='COMIC SANS MS,ARIAL' size='2' color = '#DC143C'><b>Your IP address is: " . $serverIP . "</b>\")";
?>

ess
09-04-2008, 01:56 PM
Philip M, sorry if I offended you in anyway, but I didn't say that Java == JavaScript!!!

I wasn't disagreeing totally...I was just stating that it is possible to obtain user's ip, machine name etc. by way of interfacing JavaScript with JVM or Java Virtual Machine if you like...therefore, (regardless of how this is accomplished) it is possible to obtain user's ip address, etc using JavaScript...if JVM is available....or Flash is available for that matter.

Further, most internet user's these days use Routers...and if you were to log user's addresses using PHP (as in your example above), you will only be able to get the external IP address of that user...and you won't be able to read their internal IP.

My previous example shows how to get the user's internal IP address....and if you tweak it a little...you can even find out the number of devices connected in their internal network.

That might not be the purpose that martynball is after....nonetheless, you can combine a script or programming language with JS...to collect various info about the user if that is your requirement.

Once again, I am sorry if I offended you in anyway.

Cheers
~E

Spudhead
09-04-2008, 02:13 PM
var userIp = new java.net.InetAddress.getLocalHost();

Dunno about you, but that returns "localhost/127.0.0.1" on my machine. Probably not the most useful IP address in the world :D

ess
09-04-2008, 03:24 PM
Are you running this script from a local web server?

I tested the script without utilizing a server....straight from my Desktop...which could be why the results are different.

Try running it from a remote server and see if the results are different?

Cheers
~E

Philip M
09-04-2008, 03:33 PM
Philip M, sorry if I offended you in anyway, but I didn't say that Java == JavaScript!!!

I wasn't disagreeing totally...I was just stating that it is possible to obtain user's ip, machine name etc. by way of interfacing JavaScript with JVM or Java Virtual Machine if you like...therefore, (regardless of how this is accomplished) it is possible to obtain user's ip address, etc using JavaScript...if JVM is available....or Flash is available for that matter.



ess - I am not in any way offended, but I felt that you were moving away from what the OP actually wanted. I deliberately used the word "capture" to mean permenantly store or write to file in some way (as opposed to display the user's IP to the user himself - not too useful). We agree that JavaScript alone cannot do that.



Further, most internet user's these days use Routers...and if you were to log user's addresses using PHP (as in your example above), you will only be able to get the external IP address of that user...and you won't be able to read their internal IP.


Yes, a very good and valid point.



My previous example shows how to get the user's internal IP address....and if you tweak it a little...you can even find out the number of devices connected in their internal network.

That might not be the purpose that martynball is after....nonetheless, you can combine a script or programming language with JS...to collect various info about the user if that is your requirement.

Once again, I am sorry if I offended you in anyway.

Cheers
~E


As I say,I am sure that no offence was meant and none was taken.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum