CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2012
    Posts
    1

    Question 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?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    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.

  3. #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

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    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.

  5. #5
    Join Date
    Jun 2009
    Posts
    113

    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>
    <&#37;
    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
  •  





Click Here to Expand Forum to Full Width

Featured