4

我目前在同一台服务器上运行两个域。两个网站都使用相同的文件。

是否可以根据用户访问的域使用 javascript 或 jquery 或其他东西来显示某些页面内容?

例如。如果用户来自“www.site1.com”,我可以让页面显示与从“www.site2.com”访问不同的 CSS 模板。

我希望这是有道理的。谢谢。

4

3 回答 3

1

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.

于 2013-05-14T20:03:31.747 回答
0

利用$_SERVER['SERVER_NAME']

你也可以检查 $_SERVER 变量

var_dump($_SERVER);

PHP 手册:$_SERVER

于 2013-05-14T20:11:22.730 回答
-1

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

于 2013-05-14T20:03:00.300 回答