简体   繁体   English

根据域显示不同的内容

[英]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? 是否可以利用javascript或jquery或其他东西根据用户从哪个域访问来显示某些页面内容?

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". 如果用户从“www.site1.com”到达,我可以使页面显示与从“www.site2.com”访问时不同的css模板。

I hope this makes sense. 我希望这是有道理的。 Thanks. 谢谢。

In PHP: Get current domain 在PHP中: 获取当前域名

In JavaScript: Get The Current Domain Name With Javascript (Not the path, etc.) 在JavaScript中: 使用Javascript获取当前域名(不是路径等)

Then you can do some if/else statements in either PHP or JavaScript and display your content accordingly. 然后,您可以在PHP或JavaScript中执行一些if / else语句,并相应地显示您的内容。

use $_SERVER['SERVER_NAME'] 使用$_SERVER['SERVER_NAME']

and you can also check $_SERVER variable 你也可以检查$ _SERVER变量

var_dump($_SERVER); 后续代码var_dump($ _ SERVER);

PHP manual:$_SERVER PHP手册:$ _ 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 ). 您可以检查$_SERVER['HTTP_REFERER']值来尝试来了解的用户已经来了(它没有任何关系,他已经来到申请的域名)。 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). 此值可能很有用,但您不应该依赖它,因为它可以轻松更改(它是Web浏览器在链接后可能设置的标题之一)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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