identifying sub domains in webpage

Hey all, just wondering if there is a way to identify which subdomain is being used on the page, there fore displaying a specific image for it

eg.

sub1.domain.com.au > image of monkey

sub2.domain.com.au > image of tiger

the pages are identical, just need an if statement to identify the subdomain

Thanks in advance
Graemewebber4technologiesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom BeckCommented:
Something like this should work (javascript).
var wl = window.location.href;
	wl = wl.substr(0, wl.indexOf('.'));
	wl = wl.substr(wl.indexOf('/')+2);
	if(wl === 'sub1'){
		//display image of monkey
	}else if(wl === 'sub2'){
		//display image of tiger
	}

Open in new window

0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
To get the sub domain  name server side you could use the following server variable:

url = Request.ServerVariables("SERVER_NAME")

then you can do an if statement on that variable and display the appropriate image
0
Graemewebber4technologiesAuthor Commented:
Big Monty, are you able to give an IF statement example?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Sure no problem, try the code below and let me know if you have any questions.

url = Request.ServerVariables("SERVER_NAME") 
If InStr( url, "sub1" ) > 0 then 
    Response.Write "<img  src=' monkey.png' />
elseif InStr( url, "sub2" ) > 0 then 
    Response.Write "<img  src=' tiger.png' />
end if

Open in new window


If you have multiple conditions you want to check, just add them in the IF statement.
0
Graemewebber4technologiesAuthor Commented:
Thanks for the BigMonty, it sends back the whole domain, not the just the sub (which is what i would like)

ideas?
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
it sends back the whole domain, not the just the sub (which is what i would like

not sure what you mean by this. the code just checks for any occurrence of the string "sub1" in the first if statement and for the string "sub2" in the 2nd if statement.

if you do a Response.Write URL, what do you get?
0
Graemewebber4technologiesAuthor Commented:
Hi BigMonty. I get the full domain. Eg

Sub1.maindomain.com

I just would like sub1 as the outcome
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
you had originally asked for an IF statement, which is what I gave you and should work. to extract the exact sub domain name, you can do something like:

url = Request.ServerVariables("SERVER_NAME")
subDomain = Left( url, InStr( url, "." ) - 1 )
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Graemewebber4technologiesAuthor Commented:
Looks a treat! thank you very much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.