Jump to content

Printing the IP Address From Which the Site is Viewed on Screen?


glassfish

Recommended Posts

This script ...

<?php

    echo "Your IP Address: <br/>";
    print_r($_SERVER['REMOTE_ADDR']);

?>

... prints:

::1

I am looking to have the IP address from which the site is viewed printed on screen. What is the issue, here, with the script I have?

 

I have been trying this on localhost and I am using XAMPP.

Link to comment
Share on other sites

That is what $_SEVER['REMOTE_ADDR'] is for. It returns the IP address to the remote user.

 

You are getting  ::1  because you are accessing your server locally using IPv6. To see 127.0.0.1 as the IP you need to use IPv4.

 

To use the IPv4 either uncomment   ::1 localhost   from your hosts file (or disable IPv6 on your Network Adapter - not recommended).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.