Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    IP Logging with Name?

    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.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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.
    Last edited by Philip M; 09-03-2008 at 04:46 PM.

  • #3
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    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

    PHP Code:
    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
    Last edited by ess; 09-03-2008 at 07:43 PM.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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.

    PHP Code:
    <?
    //"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>\")";
    ?>
    Last edited by Philip M; 09-04-2008 at 07:28 AM.

  • #5
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    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
    Last edited by ess; 09-04-2008 at 01:59 PM.

  • #6
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Quote Originally Posted by ess View Post
    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

  • #7
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    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

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by ess View Post
    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.
    Last edited by Philip M; 09-04-2008 at 03:35 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •