Solved

PHP Get user remote domain name

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

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 108

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now