简体   繁体   中英

Display different content based on domain

I currently run two domains on the same server. Both websites use the same files.

Is it possible to utilize javascript or jquery or something else to display certain page content based on which domain the user is accessing from?

For example. If user arrives from "www.site1.com" can I make the page display a different css template than if they access from "www.site2.com".

I hope this makes sense. Thanks.

In PHP: Get current domain

In JavaScript: Get The Current Domain Name With Javascript (Not the path, etc.)

Then you can do some if/else statements in either PHP or JavaScript and display your content accordingly.

use $_SERVER['SERVER_NAME']

and you can also check $_SERVER variable

var_dump($_SERVER);

PHP manual:$_SERVER

You can check the $_SERVER['HTTP_REFERER'] value to try to learn where from your user has came (it has nothing to do with the domain name of application he has came to ). This value might be useful but you shouldn't depend on it, because it can be easily changed (it's one of the headers web browser may set when following a link).

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