PDA

View Full Version : if statement based on domain name


space cowboy
01-31-2008, 03:10 PM
Hey, am a bit of a newbie to asp so go gentle! :eek:

I have 2 domain names: www.tascomms.co.uk and www.tascomms.mobi, they both point to the same site.

What I want is when people go to the site through the .co.uk domain they are issued one style sheet and if they go through the .mobi domain they are issued another. This is my code so far:



<%
domainname = Request.ServerVariables("SERVER_NAME")

response.write domainname

IF domainname = www.tascomms.co.uk THEN
%>
<link rel="stylesheet" href="css/screen.css" type="text/css" media="screen" />
<%
END IF

IF domainname = www.tascomms.mobi THEN
%>
<link rel="stylesheet" href="css/handheld.css" type="text/css" media="handheld" />
%>
END IF

%>


This keeps bringing up an error saying "object required"

can anyone help?

cheers :thumbsup:

Roelf
01-31-2008, 03:36 PM
i think you have to put the domainnames you are checking against between quotes:
IF domainname = "www.tascomms.co.uk" THEN

space cowboy
01-31-2008, 03:48 PM
i think you have to put the domainnames you are checking against between quotes:
IF domainname = "www.tascomms.co.uk" THEN


nope, ive tried that and still doesnt work! :eek::mad:

Roelf
01-31-2008, 04:13 PM
the red %> should be other way around : <%


<%
domainname = Request.ServerVariables("SERVER_NAME")

response.write domainname

IF domainname = www.tascomms.co.uk THEN
%>
<link rel="stylesheet" href="css/screen.css" type="text/css" media="screen" />
<%
END IF

IF domainname = www.tascomms.mobi THEN
%>
<link rel="stylesheet" href="css/handheld.css" type="text/css" media="handheld" />
%>
END IF

%>

space cowboy
01-31-2008, 04:47 PM
that was just my mistake in typing it into here....

still doesnt work though.

Roelf
01-31-2008, 05:01 PM
what is the output from the response.write you have?

space cowboy
02-05-2008, 05:50 PM
the responce.write is returning the URL (exatly how it should) which is why I dont understand why the whole thing isnt working!


AGGGGGGGGGHHHHHHHHHHHHHHHHHHHHJ

angst
02-05-2008, 06:33 PM
if this doesn't work, then there's something else wrong with your script thats not displayed here.


<%
domainname = Request.ServerVariables("SERVER_NAME")
If cstr(domainname) = "www.tascomms.co.uk" Then
response.write "<link rel='stylesheet' href='css/screen.css' type='text/css' media='screen' />"
ElseIf cstr(domainname) = "www.tascomms.mobi" Then
response.write "<link rel='stylesheet' href='css/handheld.css' type='text/css' media='handheld' />"
End If
%>

Morgoth
02-06-2008, 10:33 PM
http://www.morgoth.sonnexh.com/images/emot-code.gif
<% Option Explicit
Dim domainname, stylesheet
domainname = LCase(Request.ServerVariables("SERVER_NAME") )

'response.write domainname

If domainname = "www.tascomms.co.uk" Then
stylesheet = "screen"
ElseIf domainname = "www.tascomms.mobi" Then
stylesheet = "handheld"
Else
stylesheet = "default"
End If
%>
<html>
<head>
<link rel="stylesheet" href="css/<%=stylesheet%>.css" type="text/css" media="<%=stylesheet%>" />
</head>
<body>
</body>
</html>

That worked for me. Make sure you know all the methods that users can type the URL (with the 'www.' and without?), or else it will display the 'default' style sheet. :eek:

Whatever Jr.
02-07-2008, 09:16 AM
Just use Instr() to filter out the 'mobi'-part and you'll be fine.

Tom

Morgoth
02-07-2008, 04:18 PM
Just use Instr() to filter out the 'mobi'-part and you'll be fine.

Tom

http://www.morgoth.sonnexh.com/images/emot-code.gif

<% Option Explicit
Dim domainname, stylesheet
domainname = LCase(Request.ServerVariables("SERVER_NAME"))

'response.write domainname

If InStr(domainname,"mobi") > 0 Then
stylesheet = "handheld"
Else
stylesheet = "screen"
End If
%>
<html>
<head>
<link rel="stylesheet" href="css/<%=stylesheet%>.css" type="text/css" media="<%=stylesheet%>" />
</head>
<body>
</body>
</html>


If "mobi" is found in 'domainname' then 'stylesheet' will be "handheld" otherwise 'stylesheet' will always be "screen".

There are many ways to write this code, you should do it that best fits your needs. The method I posted before could also be written with a select case statement so you can use multiple style sheets for multiple domains.
http://www.morgoth.sonnexh.com/images/emot-code.gif

<%...
Select Case domainname
Case "www.tascomms.co.uk"
stylesheet = "screen"
Case "www.tascomms.mobi"
stylesheet = "handheld"
Case "www.tascomms.com"
stylesheet = "green"
Case "127.0.0.1"
stylesheet = "notpublic"
Case "www.tascomms.org"
stylesheet = "eco"
Else Case
stylesheet = "default"
End Select
...%>