www.webdeveloper.com
Results 1 to 6 of 6

Thread: Display a user's website IP address..?

  1. #1
    Join Date
    Jul 2004
    Posts
    53

    Display a user's website IP address..?

    Hi there, I am a newbie to this forum so please forgive me if I have posted this in the wrong section!

    I am working on a user information page (for a hosting control panel). I need to be able to show the user what their domain name is (ie. it is a list of things about their local and remote settings and hosting account info on a phone support page).

    However, our provider doesn't support extracting this data from their database. Therefore, thinking laterally, the only way (I can think of) to provide this info would be to check the http_referer (ip address?) and change that into a domain name (via DNS).

    How would I do this?

    The page is currently using ssi to display the user's own (local) IP address and Java to display which plugins they have installed (Flash, Acrobat, SVG, Shockwave etc...). I don't care which scripting language it is in as long as I can still provide the local IP address...

    ...any ideas would be much appreciated.

  2. #2
    Join Date
    May 2004
    Location
    FL
    Posts
    3,447
    I am not sure how you have set-up the SSI's but you can get the local IP address by using the following (on an Apache system):

    Code:
    %REMOTE_ADDR
    Lee

  3. #3
    Join Date
    Jul 2004
    Posts
    53
    This code is within a SHTML file (obviously I have chopped out all the jibberish HTML mark-up).

    <head>

    <SCRIPT LANGUAGE="JavaScript">
    var ip = '<!--#echo var="REMOTE_ADDR"-->';
    </script>

    </head>

    <body>

    <script>document.write(ip);</script>

    </body>
    I really am very much a newbie to scripting!

  4. #4
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    Oh, you need to give your page a .php extension and use the PHP code tags.
    Code:
    <head>
    
    <SCRIPT LANGUAGE="JavaScript">
    var ip = '<?php echo $_SERVER['REMOTE_ADDR']; ?>';
    </script>
    
    </head>
    
    <body>
    
    <script>document.write(ip);</script>
    
    </body>
    That should return the clients IP address and print it to the source code, so you can use it in your JavaScript.

    The $_SERVER[] collection holds details about the server and client machines.

    Regards,
    Andrew Buntine.

  5. #5
    Join Date
    Jul 2004
    Posts
    53
    Thank you so much for your help.

    I have found an even easier way to obtain this info:

    <? $HTTP_REFERER ?>

    However, I need some more help.

    The result of the action is too much info, as I get:

    http://domain-name.co.uk/~dedop/refer.htm
    or
    http://www.domain-name.co.uk/~dedop/refer.htm

    and all I want is www.domain-name.co.uk .

    How would I strip / trim the un-necessary information out in PHP?

  6. #6
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    You will need to use the str_replace function to remove the 'http://' substring. You also have to split the string into array and take the first index.
    Code:
    $newUrl = str_replace("http://", "", $HTTP_REFERER);
    $newUrl = split("/", $newUrl, 2)[0];
    echo "$newUrl";
    That should print out www.domain-name.co.uk

    Regards,
    Andrew Buntine.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles