complicated include?

C

chris leeds

I'm going to be using some pages as server side includes (ASP) but I can't
be confident that the user who will be editing these will be reliable enough
to make sure there is no head+body tags.

does anyone know of an example or article on how I might make the include
only take the stuff between the <body> tags? kind of like an fp include but
in real time?

TIA

--
The email address on this posting is a "black hole". I got tired of all the
spam.
Please feel free to contact me here:
http://nedp.net/contact/
--
 
T

Thomas A. Rowe

Use the FP Include to include the content that will be updated by the client. Use the ASP include
for content that is loaded before the <HTML> tag

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
 
C

chris leeds

but I'm spanning subwebs (to keep the client out of the main web).
I'm looking for something that'll read what's between the <body> tags and
include it real time. like a FrontPage include only "run time".
 
J

Jim Buyens

Write an ASP page that reads a given HTML file into a
variable.

Next, find the string "<body" and then the next ">".
Delete everything up to that point.

intBodBeg = InStr(lcase(strPage), "<body")
if intBodBeg >0 then
intBodEnd = instr(intBodBeg, strPage, ">")
if intBodEnd > 0 then
strPage = mid(strPage, intBodEnd + 1)
end if
end if

Next, find the string "</body" and discard everything from
that point onward.

intBodEnd = instr(lcase(strPage), "</body")
if intBodEnd > 0 then
strPage = left(strPage, intBodEnd - 1)
end if

Then write whatever is left into the response stream.

response.write strPage

Please note, however, that if you accept the filename from
a form field or query string, an unscrupulous visitor
could feed in odd filenames and browse data from all over
your server. So, make sure you edit the file name and
verify it contains no slashes, backslashes, ..'s and so
forth.

This approach has the added advantage that you ASP pages,
containing program code, can be in a different subweb than
the pages that the users update.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
C

chris leeds

Thanks Jim,
this is pretty much what I was looking for.
If you, or anyone else, knows of a resource (tutorial or example) that goes
into the detail about what and how each of these lines works I'd appreciate
it.

I can "sort of" understand what you've written but I lack enough underlying
skill to put it into action with any kind of confidence.
 
J

Jim Buyens

chris leeds said:
Thanks Jim,
this is pretty much what I was looking for.
If you, or anyone else, knows of a resource (tutorial or example) that goes
into the detail about what and how each of these lines works I'd appreciate
it.

I can "sort of" understand what you've written but I lack enough underlying
skill to put it into action with any kind of confidence.

Oh, all right, just because someone else recently asked the same
question.

Here's a complete page that does the job. If you save this page as
includebody.asp and then browse

includebody.asp?inc=content.htm

it will display the body section of content/content.htm whereever the

<%IncludeBody(request("inc"))%>

tag appears.

To modify the path from the page that contains the IncludeBody
subroutine to the page whose body section you want to include, modify
this statement.

const IncludePath = "content/"

<%option explicit%>
<html>
<head>
<title>Include Body Example</title>
</head>
<body>
<%
Sub IncludeBody(aUrl)
const ForReading = 1
const FormatAscii = 0
const IncludePath = "content/"
Dim regEx
Dim bodyUrl
Dim fso
Dim physFile
Dim tsPage
Dim strPage
Dim intBodBeg
Dim intBodEnd

bodyUrl = trim(aUrl)
If bodyUrl = "" Then
response.write "No file specified."
Exit Sub
End If

' Verify syntax of include URL is alphanumeric.alphanumeric
' (To avoid file system exploits.)
Set regEx = New RegExp
regEx.Pattern = "^[a-zA-Z0-9]+\x2e[a-zA-Z0-9]+$"
If Not regEx.Test(bodyUrl) Then
response.write "Illegal file name."
Exit Sub
End If

' Translate include URL to physical path and verify it exists.
set fso = server.createobject("scripting.filesystemobject")
physFile = server.mappath(IncludePath & bodyUrl)
If Not fso.FileExists(physfile) Then
response.write "File not found."
Exit Sub
End If

' Copy physical file into strPage variable.
set tsPage = fso.OpenTextFile(physFile, ForReading, False,
FormatAscii)
strPage = tsPage.ReadAll
tsPage.close

' Chop off everything up to and including the <body> tag.
intBodBeg = InStr(lcase(strPage), "<body")
If intBodBeg > 0 Then
intBodEnd = instr(intBodBeg, strPage, ">")
If intBodEnd > 0 Then
strPage = mid(strPage, intBodEnd + 1)
End If
End If

' Chop off the </body> tag and anything that follows.
intBodEnd = instr(lcase(strPage), "</body")
If intBodEnd > 0 Then
strPage = left(strPage, intBodEnd - 1)
End If

' Send whatever remains to the visitor.
response.write strPage
End Sub
%>
<h1 align=center>Include Body Example</h1>
<%IncludeBody(request("inc"))%>
<hr>
<p>Page Footer</p>
</body>
</html>

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

word to frontpage trick? 20
opinions on a rough template? 3
smile 11
odd one. 8
php with fp 2002 vs. 2003 5
Included content not included 3
ASP Include page not working 8
New Table via ASP? 17

Top