简体   繁体   中英

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.

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

您可以检查以下内容:

echo $_SERVER['HTTP_HOST']

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM