Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Does ASP have a require function, similar to the require function in PHP?

Posted on 2003-03-07
4
Medium Priority
?
306 Views
Last Modified: 2012-06-27
In PHP, you can use the require function. It is similar to the include directive in C or the require directive in Perl.  In PHP, when the require function is processed, it is replaced with the file that it points to.  This is a good way to separate HTML from PHP and to reuse code.  For example:

<?
include("claFunc.inc");
require("tag-head.html");
require("tag-styles.html");
require("tag-head-end.html");
require("tag-body.html");

// here is where the body of this particular page would be built...
// could be just print statements of html, function calls, etc...

require ("tag-endpage.html");
?>

The require functions above open the html files they point to.  The contents of those files, in this case, pure html, will become part of the resulting page...  

I want to accomplish something similar in ASP.  Maybe ASP has a similar function and I'm just missing it, as i am still somewhat new to ASP...

<%
#include file="somefile.inc"
require file="tag-head.html"
require file="tag-styles.html"

// body of page goes here....

require file="tag-endpage.html"
%>

Thanks in advance!

Preece
0
Comment
Question by:Preece
4 Comments
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8090677
what you can do is create an INCLUDE file (thefile.inc) in which you set your script delimiters and input your code:

TheIncludeFile.inc:

<%
function GetLastURL()

GetLastURL=Request.ServerVariables("HTTP_REFERER")

end function
%>

and then simply include it in your HTML document:

<html>
<head>
</head>
<body>
ASSUMING THE FILE IS IN THE SAME FOLDER:
<!-- #INCLUDE FILE="TheIncludeFile.inc" -->
ASSUMING IT IS IN A DIFFERENT FOLDER
<!-- #INCLDE VIRTUAL="Http://ServerName/SpecificFolder/SubsIfAny/TheIncludeFile.in" -->

so then you can use the function GetLastURL in your code anywhere on this page!
<%
Previous=GetLastURL()
%>

</body>
</html>

and there you have it...

Hope this helps!

MaxOvrdrv2
NOTE: you must include the file on every page!
0
 
LVL 28

Accepted Solution

by:
sybe earned 200 total points
ID: 8090679
In ASP you can use the SSI commands, like this
<!--#include file="myinclude.asp"-->

It does not matter if the included file contains ASP or HTML or both.
Note that you should use it outside of the <% and %> tags.
0
 
LVL 15

Expert Comment

by:gladxml
ID: 8092167
Preece,

Try to check out the link.. might help...

http://www.4guysfromrolla.com/webtech/faq/Intermediate/faq7.shtml
0
 
LVL 12

Author Comment

by:Preece
ID: 8163311
Thanks, this works well!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question