CJT3
CJT3

Reputation: 2908

Detect if navigated to by Domain Name or IP address

Is it possible to detect whether a user navigated to my site via Domain Name or by IP Address? Google isn't being very helpful.

Upvotes: 0

Views: 384

Answers (3)

Oussama Jilal
Oussama Jilal

Reputation: 7739

You can check this :

echo $_SERVER['HTTP_HOST']

Upvotes: 2

JarroVGIT
JarroVGIT

Reputation: 5269

Yes it is: In PHP you have the server-variables, and this one you need:

$_SERVER['HTTP_REFERER'];

This will give you the domain you visitor came from :)

Upvotes: 1

Tadeck
Tadeck

Reputation: 137290

Yes, you can eg. use client-side, in JavaScript (judging from the tags it is acceptable):

window.location.hostname

as per documentation: https://developer.mozilla.org/en-US/docs/DOM/window.location

Or server-side, in PHP:

$_SERVER['HTTP_HOST']

as per documentation: http://php.net/manual/en/reserved.variables.server.php

Upvotes: 2

Related Questions