|
-
February 1st, 2012, 08:15 PM
#1
Loading includes based upon site name
Is it possible to have a script setup that will load a include file based upon site name?
What I want to do is have include file that will load based upon if the domain is like dev.domain or www.domain
In other words,
http://dev.domain.com ----> include file dev.asp
http://www.domain.com ----> include file live.asp
The reason for this is I want to make it easier to deploy asp pages with the minimal amount of changes from Dev to live.
Anyone know if this is possible?
-
February 1st, 2012, 10:34 PM
#2
Re: Loading includes based upon site name
The server variable SERVER_NAME will get you the domain. Then you just include the proper file.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
March 8th, 2012, 06:52 AM
#3
Re: Loading includes based upon site name
Code:
<?php
$homepage = "/subdirectory/";
$currentpage = $_SERVER['REQUEST_URI'];
if($homepage==$currentpage) {
include('file you want to include');
}
?>
New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.
www.ethans-space.com
-
March 8th, 2012, 10:19 AM
#4
Re: Loading includes based upon site name
A PHP solution will not work for an ASP implementation.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
March 12th, 2012, 05:19 AM
#5
Re: Loading includes based upon site name
This isn't as straightforward as I first thought. I tried a little test as follows:
Code:
<html>
<head>
<%
Dim IncludeFile
If LCase(Request.ServerVariables("SERVER_NAME"))="dev.domain.com" Then
IncludeFile = "dev.asp"
ElseIf UCase(Request.ServerVariables("SERVER_NAME"))="www.domain.com" Then
IncludeFile = "live.asp"
Else
End If
%>
<!--#INCLUDE FILE=<%=IncludeFile%>-->
</head>
<body>
</body>
</html>
But it failed, I think because Server Side Includes are processed before the ASP.
Can you not simply do a redirect within your ASP? Like this:
Code:
If LCase(Request.ServerVariables("SERVER_NAME"))="dev.domain.com" Then
Response.Redirect Server.MapPath("dev.asp")
ElseIf LCase(Request.ServerVariables("SERVER_NAME"))="www.domain.com" Then
Response.Redirect Server.MapPath("live.asp")
End If
If your include file isn't ASP and is pure JS/HTML, you could load it into the page:
Code:
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.OpenTextFile(Server.MapPath(IncludeFile))
Response.Write objFile.ReadAll
objFile.Close
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|