Solved

PHP Get user remote domain name

Posted on 2014-03-26
3
1,339 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
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.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

623 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