Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP Get user remote domain name

Posted on 2014-03-26
3
Medium Priority
?
1,436 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
  • 2
3 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

886 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