Results 1 to 10 of 10

Thread: Getting a user's ip address

  1. #1
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Question Getting a user's ip address

    Ok, I have a form, I want to make sure the same person isn't just making new accounts with the same IP address, so I want to make sure that I can grab there IP Address, and then keep it to see if anyone is making multiple accounts...

    I already tried this script but it didn't work, because I think its a little cheaply written...

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    
    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->
    
    <!-- Begin
    // http://www.kdcgrohl.com
    
    // Depending on your server set-up,
    // you may need to use the ".shtml"
    // extension [instead of the "html"
    // or "htm"] as the script uses Server
    // Side Includes. To display in the
    // title bar, exclude the
    //"<title></title>" code from the page.
    
    // This part gets the IP
    var ip = '70.16.235.110';
    
    // This part is for an alert box
    alert("Your IP address is "+ip);
    
    // This part is for the status bar
    window.defaultStatus = "Your IP address is "+ip;
    
    // This part is for the title bar
    document.write("<title>Your IP address is "+ip+"</title>");
    //  End -->
    </script>
    I'm not advertising any websites, I just want to know how I can grab the user's ip address when they fill out my form *basicly if you can get it to a
    Code:
    document.write("<input type='text' value='"+ipaddressfunction+"' name='userip'/ readonly='true'>
    so it can come out like that, that would be great, I don't want it as an alert or in the status bar, because you never look there unless ure told to, loading something, or looking to see where ure being taken...

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <input type="text" value="<!--#echo var="HTTP_REMOTE_ADDR"-->" name="userip" readonly="readonly">
    ... if you're using SSI as the original script assumed (although that one didn't use it... did you perhaps copy the source from the page rather than the source provided?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    I tried the source provided, but it still didn't work, and SSI? whats that? never heard of it... oh and it didn't work... I don't know why... i tried with it in document.write and without, it didn't work for both...

    If there is a PHP way of doing this thats also ok...

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You can do it one of two ways with PHP. Either the route that you were going to take:

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    
    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->
    
    <!-- Begin
    // http://www.kdcgrohl.com
    
    // Depending on your server set-up,
    // you may need to use the ".shtml"
    // extension [instead of the "html"
    // or "htm"] as the script uses Server
    // Side Includes. To display in the
    // title bar, exclude the
    //"<title></title>" code from the page.
    
    // This part gets the IP
    var ip = '<?php echo $_SERVER['REMOTE_ADDR'];?>';
    
    // This part is for an alert box
    alert("Your IP address is "+ip);
    
    // This part is for the status bar
    window.defaultStatus = "Your IP address is "+ip;
    
    // This part is for the title bar
    document.write("<title>Your IP address is "+ip+"</title>");
    //  End -->
    </script>
    or like so (Just place where you want to display it:

    Code:
    <?php echo $_SERVER['REMOTE_ADDR'];?>
    (Note: This has to be in a php enabled page so that it parses correctly.)
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    Unfortunitly I can't view PHP pages at the moment *server is holding it self hostage, i'll be fine* , but could someone check to see if this works?
    Code:
    <?php echo "<input type='text' value='$_SERVER['REMOTE_ADDR']' name='useripaddress' readonly='true' />?>
    thanks for testing it! *You don't need to send it, if it displays it will most likely send!* thanks!

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The following WILL work:

    Code:
    <?php echo "<input type='text' value=' " . $_SERVER['REMOTE_ADDR'] . " ' name='useripaddress' readonly='true' />" ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    k thanks a lot man

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I tried the source provided, but it still didn't work
    Did you try it with a .shtml extension as the script said?
    <?php echo "<input type='text' value='$_SERVER['REMOTE_ADDR']' name='useripaddress' readonly='true' />?>
    It won't work because that's a complex variable: you need braces around it. However, there are deeper problems: "true" is not a valid value for the readonly attribute (can only be "" or "readonly"), you shouldn't be using XHTML (at least unless you're prepared to serve it as such; since you used document.write() earlier I doubt you're doing so) and echoing strings of HTML is bad form (don't output HTML from PHP parsing mode, since it adds an unnecessary layer of parsing and detracts from readability and efficiency).
    Code:
    <input type="text" name="user_ip" readonly="readonly" value="<?php echo $_SERVER['HTTP_REMOTE_ADDR']; ?>">
    is the PHP way of doing it, or
    Code:
    <input type="text" name="user_ip" readonly="readonly" value="<?=$_SERVER['HTTP_REMOTE_ADDR']?>">
    with short tags.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    I did try with the .shtml extension but as long as Testingsite's version works, I'll be fine...

    It won't work because that's a complex variable: you need braces around it. However, there are deeper problems: "true" is not a valid value for the readonly attribute (can only be "" or "readonly"), you shouldn't be using XHTML (at least unless you're prepared to serve it as such; since you used document.write() earlier I doubt you're doing so) and echoing strings of HTML is bad form (don't output HTML from PHP parsing mode, since it adds an unnecessary layer of parsing and detracts from readability and efficiency).
    hun? So are you saying its a bad idea to do this?
    PHP Code:
    <?php
    echo "form data stuff *inputs and labels"
    ?>
    because I'm not doing that i'm doing this:

    Code:
    <script>
    document.write("formdataandcodes")
    </script>
    which prevents the user from have javascript disabled so he can pass the validation without valid content

  10. #10
    Join Date
    Oct 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Personal IP + Outside IP.... how?

    ok, so I read this thread and it was great. Now I am able to secretly grab the IP address of the person filling out the web form and place it within the email I'm sending to myself.
    (By the way, this is done within a PHP script that runs as soon as you hit Submit.. so it's not seen as part of the form)

    But here's what I found. I tested this out at work today and it did indeed give me my IP address. But this is my IP address within the company. Is there any way to additionally add the outside IP address as well? (ie: the IP address of the outside firewall or port that is used to connect them to their ISP?)

    If I needed to track down a person... the internal definitely helps, but I wouldn't be able to locate what company/location it came from.

    Thanks

Bookmarks

Posting Permissions

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