Server Side Includes (SSI) with ASP


Server Side Includes (SSI) with ASP

People often have identical sections of code spread throughout many ASP pages, typically code at the top of the page (usually referred to as the header) and the lower part of the page (the footer). Similarly, you may have code that performs a certain set of instructions that you are repeating across multiple pages. Consider an example:-

<%
If foobar="yes" then
response.write "YES!"
Else
response.write "NOT YES!"
End if
%>

Ok, ok... it's simple, but imagine that you used this on multiple pages. What's wrong with this picture?

Well... you don't have to think about that long before realising that if you ever wanted to change something about that piece of code, you'd have your work cut out. you would have to change every page... everyone has done this at some stage and luckily most usually take the steps to learn a way around this problem.

If we could save our valuable chunk of code into a file and have that file accessed whenever we needed the code, then we no longer have a problem when it comes to changing things, as we simply update one file. Include files or Server Side Includes (SSI) as they are more commonly known are a powerful way to not only save time when it comes to maintaining and updating a site, but also increase efficiency and speed of that site too!

Ok, lets see how we use an include file... to start with we need to use one of two methods. The first one allows for including files relatively. By that I mean relative to the directory the ASP file that is using the include file resides. The second method includes files virtually. Including files virtually means that the path is taken from the root directory.

Consider that we are going to have a file (/main/somefile.asp) include another file (/includes/someinclude.asp).

To demonstrate, relative inclusion, look at this:-

<%
Response.Write "executing included code now"
%>
<!--#include file="../includes/someinclude.asp"-->
<%
Response.write "done executing included code"
%>

And here, we give an example of the other method, virtual inclusion:-

<%
Response.Write "executing included code now"
%>
<!--#include virtual="/includes/someinclude.asp"-->
<%
Response.write "done executing included code"
%>

Note the slight difference between the two methods. With virtual inclusion, you can move the file that calls upon the include file anywhere without affecting the outcome, because the path is always relative to the root. The same cannot be said however for relative inclusion. If you move a file that is using relative inclusion to a different directory, you'll most likely find the relative path is no longer correct.

From the examples above, you may also notice that both methods, when calling the include do so OUTSIDE of the ASP script block. This because #include declarations are not interpreted by ASP. Include files are included before a single line of ASP is processed which means the following WONT work:-

%lt;%
Page=request.form("page")
%>
<!--#include file="../includes/<%=page%>.asp"-->

We were attempting to perform a dynamic include and I would be the first to admit that the above would be very useful indeed if in fact it were possible. I do intend to cover a few methods that work around this set back but I know you will now be itching to get started right away on using include files to even worry about this, so I will cover it in a future article.

I hope that you have found the above informative and hope it inspires you all to write code that's more efficient and more easily maintained.

Rob Collyer, experienced with 20 years programming knowledge and site administrator of www.webforumz.com - Copyright 2003-2004

Bedford Park travel from Midway .. Lockport Chicago limo O’Hare
In The News:

Double-clicking is something we all do, often without giving it a second thought. But it could be giving hackers permission to do something dangerous.
Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
Kurt the CyberGuy offers some of his easy expert tips to free up storage space on your Android if your device is running short on storage.
You can reset your internet router remotely if you're not home when your power goes out. Kurt "CyberGuy" Knutsson explains how this can be done.
The EO Canopy is a self-sustaining, solar-powered camping platform designed to provide all the comforts of home while completely off the grid.
Experts say hackers who used to focus on Windows operating systems are increasingly targeting Apple IDs as part of a new phishing campaign.
Unitree, a Chinese robotics company that developed a backflipping robot, has now introduced a humanoid robot capable of doing a side flip.
Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
According to the FBI, cybercriminals are sending extortion letters, threatening to release victims' sensitive information unless a ransom is paid.
FireSat is a satellite project designed to detect and track wildfires early, aiming to detect a fire that's the size of a classroom within 20 minutes.
Tech expert Kurt “CyberGuy" Knutsson reports that researchers have uncovered a Chrome vulnerability used in a cyber espionage campaign.
Preserving voicemails securely on Android: Tech expert Kurt “CyberGuy" Knutsson reveals easy methods to keep memories alive forever.
This phishing kit bypasses 2FA via session hijacking and real-time credential theft. Kurt “CyberGuy" Knutsson offers four ways to stay safe from Astaroth phishing attacks.
Tech expert Kurt “CyberGuy" Knutsson discusses Joby Aviation and Virgin Atlantic planning to launch 200-mph U.K. air taxis linking airports and cities.
Fake Apple virus warnings, security alerts and messages are tactics used to prompt you to call a number or click on a malicious link. The CyberGuy explains how to protect your devices.
The combination of artificial intelligence and neuroscience allows a paralyzed man to manipulate a robotic arm by using his brain to imagine movements.
With the help of artificial intelligence, sophisticated fraud techniques emerging today are virtually undetectable to the untrained eye.
Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents
If you need to free up space on your Mac, consider deleting duplicate photos in your image library. Apple makes it easy to do, and the CyberGuy explains the process.
Microsoft is discontinuing Skype in May after 22 years of service. Kurt the CyberGuy addresses other options for internet-based phone and video service.
Tron 1, a Chinese company's two-legged robot, is versatile and can walk, roll and pivot, even on rough terrain. Tron 1 stands 33 inches tall and weighs 44 pounds.
Hackers are tricking people into installing password-stealing malware by making them press keyboard shortcuts under the pretense of proving they're not bots.
Saving the voices of loved ones can be a comforting way to keep alive memories. Kurt "the CyberGuy" Knutsson explains how to preserve voicemail messages.
Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
The FBI warns that some free online document converters load malware onto people's computers, making their private information vulnerable to attack.

You Don?t Have to be Amazon.com to Achieve 12% Conversion Rates!

That's right. According to a recent study by Nielsen/NetRatings, Amazon.com... Read More

Art, Artists and the Web: Part 4--What to Do After a Website is Designed

What to do if you are an artist after you... Read More

7 Tips to Make Your Order Page Work Harder

So your prospect, Mary, is sitting at the computer reading... Read More

5 Ways to Build a Website

If you are like me you have wanted to build... Read More

The Two Most Common Mistakes That Scare Away Web Visitors

Can you imagine the hypocrisy of spending thousands of dollars,... Read More

Creating Dynamic Website Content with PHP - MySQL

Fresh website content for your visitors can be of real... Read More

9 Simple Steps to Create a Background Tiled Image Branded with Your Name

You have seen those web pages where they have the... Read More

Creating Websites that Cater to Exam Preparations

One of the things that Internet excels is disseminating information... Read More

Getting a Web Site Can Be Fast, Easy, and Inexpensive When You Know Your Options

So what do you do if need to get a... Read More

For Newer Sites, Web Marketing Depends On Titles & Links!

We all start out the same. Some have budgets, some... Read More

Free Isnt Always Good - 5 Reasons Why You Need Your Own Website

Often time I've browsed sites and seen the same thing... Read More

What YOU Should Know Before Getting A Web Site!

Everyday thousands of new businesses make the leap and take... Read More

How to Handle Web Surfers Who Disabled JavaScript

There are hundreds of millions of Web surfers today. Each... Read More

Allocating Your Web Site?s Budget Properly

I had a client say something to me the other... Read More

6 Steps To Your Own Website

A lot of people these days are interested in getting... Read More

3 Ways To Increase Your Websites Conversion rate

Everywhere you look these days, people are telling you that... Read More

How to Listen on the Web

When building a relationship, listening is more important than talking.A... Read More

Make Your Artist Website Sell!

SummaryHere's the scoop on what you must know when designing... Read More

Profitable Websites for Exclusive Industries

In the region where my company is located, South Bend,... Read More

Developing State-enabled Applications With PHP

Installment 1Developing State-enabled Applications With PHPWhen a user is browsing... Read More

Link Trades That Waste Your Time

Never has competition been so difficult in the Internet world.... Read More

Easy Steps To Website Development and Promotion

One of the most important parts of establishing a new... Read More

Free Websites & Why You Should Avoid Them

It amazes me how many people try to build serious... Read More

My Yahoo Search - Beyond Bookmarks

Yahoo has long offered email, an online calendar, notes, bookmarks,... Read More

Launch Your Own Website Today - Its Easier Than You Think!

Thousands of people are now making a living online and... Read More

Cadillac Escalade SUV rentals Basco ..