4

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.

Leafs Fan
  • 41
  • 2
  • Look at `document.domain`: https://developer.mozilla.org/en-US/docs/DOM/document.domain , or choose from the properties of `window.location`: https://developer.mozilla.org/en-US/docs/DOM/window.location#Properties (like `host`) – Ian May 14 '13 at 20:02
  • 1
    Off topic: Google doesn't like identical content being used on different domains -- not good for SEO – Timidfriendly May 14 '13 at 20:11
  • Thanks I will ook into this :) – Leafs Fan May 15 '13 at 21:02

3 Answers3

2

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.

Community
  • 1
  • 1
seangates
  • 1,467
  • 11
  • 28
0

use $_SERVER['SERVER_NAME']

and you can also check $_SERVER variable

var_dump($_SERVER);

PHP manual:$_SERVER

Michal Hatak
  • 797
  • 1
  • 9
  • 21
-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).

Wiktor
  • 2,909
  • 4
  • 17
  • 23
  • That only tells you which page referred you to the current page (if it was supplied in the headers, of course). – seangates May 14 '13 at 20:04
  • 1
    and then he says 'access from' and as the rest reads i think its clear he wants to know what site they are on now. –  May 14 '13 at 20:07