Solved

PHP Get user remote domain name

Posted on 2014-03-26
3
1,309 Views
Last Modified: 2014-03-26
Hello Experts.

There is a way to get users IP using $_SERVER['REMOTE_ADDR'], etc.
But how can i get user's domain?

I have a page that returns a json response.

that page is consulted by another website using the function "file_get_contents" and that website is "www.mydomain.org".

Can i get the domain name the consulted me ("www.mydomain.org") besides his IP address?
0
Comment
Question by:justaphase
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39955805
No.  Clients do not have a domain name.  You may coincidentally be able to do a reverse IP lookup and find that some REMOTE_ADDR are associated with a domain, but it's not something that is dependable at all.  For example, which of my 32 web sites is my REMOTE_ADDR associated with?  My email is at Gmail, but so are millions of others.  It's just not information that exists in any way that you can use.
0
 
LVL 1

Author Closing Comment

by:justaphase
ID: 39955976
You're right..
That's what i'm gonna do.
Something like this:

$array = array(
"www.domain1.com" => gethostbyname("www.domain1.com")
,"www.domain2.pt" => gethostbyname("www.domain2.pt")
,"www.domain3.org" => gethostbyname("www.domain3.org")
);

while ($ip = current($array)) {
      if ($_SERVER['REMOTE_ADDR'] == $ip) echo "it's one of my clients";
      next($array);
}

Thx for the help :)
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39956008
Before you write that while() loop you might want to look up foreach().  Just a thought.  Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question