Forums

Resolved
0 votes
On my website, I have a page where my visitors can click on PHP links to download files. At the same time, my PHP also retrieves basic information from this download us PHP like the user IP address and sends an email to us all in the background.

So, my question is this. Is there away to retrieve my visitors' domain name using their IP address from which they are requesting information if it is possible? I am running ClearOS and PHP 5.4

I did read that you have to set up your webserver for this especially enabling hostnamelookup on inside httpd.conf

I simply want to $_SERVER["REMOTE_HOST"] for my visitor's domain name.

Any hints or clues will be greatly appreciated. Thanks.
Friday, April 01 2022, 02:08 PM
Share this post:
Responses (4)
  • Accepted Answer

    Wednesday, April 13 2022, 03:08 PM - #Permalink
    Resolved
    0 votes
    Hi Nick,

    I thought I found the answer to my question, but it turns out I jumped the gun. $_SERVER["SERVER_NAME"] only returns our domain name not the domain name of the visitor's IP ADDRESS. Let me look at your suggestion and come back with more questions or thank you...

    :)
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, April 07 2022, 05:19 PM - #Permalink
    Resolved
    0 votes
    It is possible you do a reverse DNS lookup which returns the PTR record for the IP. There is only one per IP. If lots of domains use a single IP, you can't do a reverse lookup on that as it is different. PTR records are set by the ISP and some, especially business ones, allow you to change them. Many IP's done have them. Others use generic ones.
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, April 07 2022, 01:28 PM - #Permalink
    Resolved
    0 votes
    Hi Nick,

    Well, in my internet research on this, I kept getting told that it is nearly IMPOSSIBLE to do this for each server ip address it could be pointing at more than one domain name; retrieving domain name for a server from its ip address. I understood the reason why. However, there is a PHP environmental element that you can request from the visitor's server that gives you the name (Domain Name) of the server if possible; $_SERVER["SERVER_NAME"].

    To my surprise, it returned EXACTLY what I was looking for a domain for the server like www.example.com. :)

    Just putting this out here just in case someone is looking for something similar solution or an answer.

    Thank you for the reply Nick.
    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, April 06 2022, 03:44 PM - #Permalink
    Resolved
    0 votes
    It must be possible as it is done in the DHCP server app and, perhaps. in the Network Map app, so there is some PHP code for it. Where it is, I don't know, but perhaps start with /usr/clearos/apps/dhcp/libraries but I have a feeling it may lead you to app-base.
    The reply is currently minimized Show
Your Reply