Detect from URL or IP Address?

Is there a way for a “normal” webpage (ie. Javascript or PHP) to detect how it was called?

For example… If someone types in “”… the browser will load “
or if they type in “” (where xxx is my IP address)… they get the same result…

But can index.php tell which method was used to call it? and for example … redirect if it were called by IP address instead of URL?

The way that web servers and PHP pages, etc detect what host you are trying to reach is by the “host” header sent in the request. Without that, it is not possible to tell, because the browser resolves the name to the IP address before making the request. The host header is what enables virtual hosts (more than one host on a single IP address) to function at all. That is why sometimes putting the IP address in the browser does not work.

… to answer the other part of your question: yes, reading the “host” header sent with the request, the web server or page could redirect based on that value… again, that is exactly how virtual hosts work.

I hope that makes sense, I have taken a ton of allergy medication today %)

Thanks I found this… but have not yet tried it…

I don’t want my site accessed by IP only by its domain name :slight_smile:

Correct - in PHP you would find the header value here:


If it is anything but what you want it to be, you could redirect to the domain you want like this:

if ($_SERVER['HTTP_HOST']) <> "my") {

The code above has to happen before anything else is sent to the browser or you will get a “headers already sent” error.

This is called Referer and should ne found in Server Variables as John said but…
Privacy aware Websites hides their Referers so the next Website won’t know from where somebody is coming

The referrer is different from the Host header. The referrer represents the source of a link that leads to the request. Like if you click a link on google to your website - the referrer would be google, the host would be your website.

Hope that makes sense.

I don’t care where the CAME from, I care about how they decided to access MY page

Exactly - you have to read the ‘host’ header.
Your web server software will do this, you can also do it in PHP as I have outlined above.

In xojo, it may be possible to read the header here WebApplication.HTMLHeader but I am not totally sure. Anyone else want to comment on that? How do you read the request headers sent to a xojo web application?

In JavaScript :

It is indeed possible :

In Xojo Web would be the same as in PHP. Xojo has Session.Header() As String.

PHP has $_SESSION[‘HOST’] and such.