View Full Version : SSI, Server-side includes (but in a script)
cmadore
09-14-2004, 04:50 AM
I would like to accomplish the same function as a SSI (server-side include), but in a script.
Let me provide you some background as to what I would like to do:
Based upon a random number, I would like to include a page associated with that particular number. Here?s my code:
<% Function ParseSolutions
'Generate Random Number
Dim PageRnd
Randomize
PageRnd = Int((8-0+1) * Rnd + 0)
'Load up array with locations of Solution Promo pages
Dim RndSolutionsPage(8)
RndSolutionsPage(0)="frontPagePromos/solutions/enterprise-promo.htm"
RndSolutionsPage(1)="frontPagePromos/solutions/government-promo.htm"
RndSolutionsPage(2)="frontPagePromos/solutions/healthcare-promo.htm"
RndSolutionsPage(3)="frontPagePromos/solutions/higher-ed-promo.htm"
RndSolutionsPage(4)="frontPagePromos/solutions/hospitality-promo.htm"
RndSolutionsPage(5)="frontPagePromos/solutions/k-12-promo.htm"
RndSolutionsPage(6)="frontPagePromos/solutions/prof-serv-promo.htm"
RndSolutionsPage(7)="frontPagePromos/solutions/retail-promo.htm"
RndSolutionsPage(8)="frontPagePromos/solutions/sm-business-promo.htm"
End Function
%>
<!-- include file=<%=RndSolutionsPage(PageRnd)%> à
How do I dynamically (within a script) call the associated page?
This didn?t work (for obvious reasons): <!-- include file=<%=RndSolutionsPage(PageRnd)%> à
Thanks for your help. I?m just getting back to programming and honestly feel like a beginner.
C Madore
bruce
09-14-2004, 07:33 AM
I assume this is a asp page
Save the random code as an inc or asp file and add a response.write
<!--#include virtual="/include/random.asp"-->
[b]quote:Originally posted by cmadore
I would like to accomplish the same function as a SSI (server-side include), but in a script.
Let me provide you some background as to what I would like to do:
Based upon a random number, I would like to include a page associated with that particular number. Here?s my code:
<% Function ParseSolutions
'Generate Random Number
Dim PageRnd
Randomize
PageRnd = Int((8-0+1) * Rnd + 0)
'Load up array with locations of Solution Promo pages
Dim RndSolutionsPage(8)
RndSolutionsPage(0)="frontPagePromos/solutions/enterprise-promo.htm"
RndSolutionsPage(1)="frontPagePromos/solutions/government-promo.htm"
RndSolutionsPage(2)="frontPagePromos/solutions/healthcare-promo.htm"
RndSolutionsPage(3)="frontPagePromos/solutions/higher-ed-promo.htm"
RndSolutionsPage(4)="frontPagePromos/solutions/hospitality-promo.htm"
RndSolutionsPage(5)="frontPagePromos/solutions/k-12-promo.htm"
RndSolutionsPage(6)="frontPagePromos/solutions/prof-serv-promo.htm"
RndSolutionsPage(7)="frontPagePromos/solutions/retail-promo.htm"
RndSolutionsPage(8)="frontPagePromos/solutions/sm-business-promo.htm"
End Function
%>
<!-- include file=<%=RndSolutionsPage(PageRnd)%> à
How do I dynamically (within a script) call the associated page?
This didn?t work (for obvious reasons): <!-- include file=<%=RndSolutionsPage(PageRnd)%> à
Thanks for your help. I?m just getting back to programming and honestly feel like a beginner.
C Madore
</blockquote id="quote"></font id="quote">
B.
DiscountASP.NET
http://www.DiscountASP.NET
cmadore
09-15-2004, 09:54 AM
Thanks for the reply Bruce. Yes, this is an ASP page. I appreciate your reply; however, you didn't answer my question. Is there a function that will perform the equivilant of a server-side include from WITHIN a script?
Inquiring mind would like to know.
Thanks.
C.
[b]quote:Originally posted by bruce
I assume this is a asp page
Save the random code as an inc or asp file and add a response.write
<!--#include virtual="/include/random.asp"-->
[b]quote:Originally posted by cmadore
I would like to accomplish the same function as a SSI (server-side include), but in a script.
Let me provide you some background as to what I would like to do:
Based upon a random number, I would like to include a page associated with that particular number. Here?s my code:
<% Function ParseSolutions
'Generate Random Number
Dim PageRnd
Randomize
PageRnd = Int((8-0+1) * Rnd + 0)
'Load up array with locations of Solution Promo pages
Dim RndSolutionsPage(8)
RndSolutionsPage(0)="frontPagePromos/solutions/enterprise-promo.htm"
RndSolutionsPage(1)="frontPagePromos/solutions/government-promo.htm"
RndSolutionsPage(2)="frontPagePromos/solutions/healthcare-promo.htm"
RndSolutionsPage(3)="frontPagePromos/solutions/higher-ed-promo.htm"
RndSolutionsPage(4)="frontPagePromos/solutions/hospitality-promo.htm"
RndSolutionsPage(5)="frontPagePromos/solutions/k-12-promo.htm"
RndSolutionsPage(6)="frontPagePromos/solutions/prof-serv-promo.htm"
RndSolutionsPage(7)="frontPagePromos/solutions/retail-promo.htm"
RndSolutionsPage(8)="frontPagePromos/solutions/sm-business-promo.htm"
End Function
%>
<!-- include file=<%=RndSolutionsPage(PageRnd)%> à
How do I dynamically (within a script) call the associated page?
This didn?t work (for obvious reasons): <!-- include file=<%=RndSolutionsPage(PageRnd)%> à
Thanks for your help. I?m just getting back to programming and honestly feel like a beginner.
C Madore
</blockquote id="quote"></font id="quote">
B.
DiscountASP.NET
http://www.DiscountASP.NET
</blockquote id="quote"></font id="quote">
C Madore
cmadore
09-15-2004, 10:00 AM
I guess I should be more specific: I'm looking for a function that will call html from a file and then parse - all from WITHIN a script. (I'm aware that these may be 2 functions.) Please help.
Craig
[b]quote:Originally posted by cmadore
Thanks for the reply Bruce. Yes, this is an ASP page. I appreciate your reply; however, you didn't answer my question. Is there a function that will perform the equivilant of a server-side include from WITHIN a script?
Inquiring mind would like to know.
Thanks.
C.
[b]quote:Originally posted by bruce
I assume this is a asp page
Save the random code as an inc or asp file and add a response.write
<!--#include virtual="/include/random.asp"-->
[b]quote:Originally posted by cmadore
I would like to accomplish the same function as a SSI (server-side include), but in a script.
Let me provide you some background as to what I would like to do:
Based upon a random number, I would like to include a page associated with that particular number. Here?s my code:
<% Function ParseSolutions
'Generate Random Number
Dim PageRnd
Randomize
PageRnd = Int((8-0+1) * Rnd + 0)
'Load up array with locations of Solution Promo pages
Dim RndSolutionsPage(8)
RndSolutionsPage(0)="frontPagePromos/solutions/enterprise-promo.htm"
RndSolutionsPage(1)="frontPagePromos/solutions/government-promo.htm"
RndSolutionsPage(2)="frontPagePromos/solutions/healthcare-promo.htm"
RndSolutionsPage(3)="frontPagePromos/solutions/higher-ed-promo.htm"
RndSolutionsPage(4)="frontPagePromos/solutions/hospitality-promo.htm"
RndSolutionsPage(5)="frontPagePromos/solutions/k-12-promo.htm"
RndSolutionsPage(6)="frontPagePromos/solutions/prof-serv-promo.htm"
RndSolutionsPage(7)="frontPagePromos/solutions/retail-promo.htm"
RndSolutionsPage(8)="frontPagePromos/solutions/sm-business-promo.htm"
End Function
%>
<!-- include file=<%=RndSolutionsPage(PageRnd)%> à
How do I dynamically (within a script) call the associated page?
This didn?t work (for obvious reasons): <!-- include file=<%=RndSolutionsPage(PageRnd)%> à
Thanks for your help. I?m just getting back to programming and honestly feel like a beginner.
C Madore
</blockquote id="quote"></font id="quote">
B.
DiscountASP.NET
http://www.DiscountASP.NET
</blockquote id="quote"></font id="quote">
C Madore
</blockquote id="quote"></font id="quote">
C Madore
infinitedes
09-20-2004, 06:31 AM
Here is your code it has some problems:
[quote]
<%FunctionParseSolutions()</fontid="red">
'GenerateRandomNumber
DimPageRnd
Randomize
PageRnd=Int((8-0+1)*Rnd+0)
'LoaduparraywithlocationsofSolutionPromopages
DimRndSolutionsPage(8)
RndSolutionsPage(0)="frontPagePromos/solutions/enterprise-promo.inc</fontid="red">"
'includedfilesmustbeeitherasporincextensionsappare ntly
RndSolutionsPage(1)="frontPagePromos/solutions/government-promo.htm"
RndSolutionsPage(2)="frontPagePromos/solutions/healthcare-promo.htm"
RndSolutionsPage(3)="frontPagePromos/solutions/higher-ed-promo.htm"
RndSolutionsPage(4)="frontPagePromos/solutions/hospitality-promo.htm"
RndSolutionsPage(5)="frontPagePromos/solutions/k-12-promo.htm"
RndSolutionsPage(6)="frontPagePromos/solutions/prof-serv-promo.htm"
RndSolutionsPage(7)="frontPagePromos/solutions/retail-promo.htm"
RndSolutionsPage(8)="frontPagePromos/solutions/sm-business-promo.htm"
EndFunction
%>
</CODE>
This function was a good start but it has some major problems.
First of all you do not want or need an array of your web pages.
All you really need is that random number part and a Select Case
[quote]
<%
DimPageRnd
Randomize
PageRnd=Int((8-0+1)*Rnd+0)
SelectCasePageRnd
Case1
%>
<!--includefile="frontPagePromos/solutions/enterprise-promo.inc</fontid="red">"
<%Case2%>
<!--includefile="etc."-->
<%EndSelect%>
</CODE>
Owen
Not in classic ASP.
You can include a file.
Also you can make a seperate ASP file as a class file, then include it in your main ASP file. Create an object in that file to the class and reference functions/subs from that.
Also, you can open a text/html file and then write it to the page in ASP. You can create templates and then using script open them in the script and change (replace) things in them and the write them to the screen.
Only other option is to use javascript to call the script but then it gets complicated, but thats another way to do it.
eg:
<script language="JavaScript" src="RndSolutionsPage.asp"></script>
or calling querystrings in the ASP page:
<script language="JavaScript" src="RndSolutionsPage.asp?rnd=1"></script>
and same but say using a VBscript variable on the loading page:
<script language="JavaScript" src="RndSolutionsPage.asp?rnd=<%=PageRnd%>"></script>
ONE LAST WAY, is to use an img tag, depends on what you want to do as it wont do much, compared to the above. Thats how I use to use my tracking scripts I wrote (been a while).
Eg: <img src="tracking.asp" width="1" height="1" border="0">
Rory
vBulletin® ©Jelsoft Enterprises Ltd.