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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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

Big MontyWeb Ninja at largeCommented:
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
Graemewebber4technologiesAuthor Commented:
Big Monty, are you able to give an IF statement example?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Big MontyWeb Ninja at largeCommented:
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.
Graemewebber4technologiesAuthor Commented:
Thanks for the BigMonty, it sends back the whole domain, not the just the sub (which is what i would like)

ideas?
Big MontyWeb Ninja at largeCommented:
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?
Graemewebber4technologiesAuthor Commented:
Hi BigMonty. I get the full domain. Eg

Sub1.maindomain.com

I just would like sub1 as the outcome
Big MontyWeb Ninja at largeCommented:
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 )

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