In Part 1 we looked at what was needed to get the
script to work to display a truly printer-friendly format. In this part we'll look two shortcomings of the
system and examine the source code to the
First off, the shortcoming. Since the printer-friendly format exists in a directory separate from the articles
PrintPage.asp format on 4Guys is in the
/ASPScripts directory while articles,
FAQs, SQLGuru questions, and other information are in the
/webtech/sqlguru and others),
it is essential that all the hyperlinks in the articles are non-relative.
Non-relative URLs are those that are not dependent upon the location of the current ASP page; URLs beginning
are non-relative. Relative URLs are ones like
If relative URLs are used, in the printer-friendly rendition the hyperlinks will be broken. For example, if in an article I have the following hyperlink:
Then in the printer-friendly format, if someone clicks on the hyperlink, they will be taken to:
/ASPScripts/092298-3.shtml, which doesn't exist and will return a 404. How annyoing!
Therefore, I make certain to use non-relative URLs in all of the articles. For example, the above hyperlink
would be recoded to read:
/webtech/ before the article URL ensures that the printer-friendly format will not produce
dead (or erroneous) links.
A second shortcoming that merits great warning is the fact that with the
clever person could view the source to your ASP scripts! For instance, imagine that the user entered the
following URL into their browser:
they could view the source to the our Search Engine (they would need to do View/Source once they entered this URL).
Therefore, in the
PrintPage.asp script a line of code ensures that users only view printer-friendly
versions of articles form the
/webtech/ directory of one of its subdirectories. Furthermore, an even
cleverer person could enter:
bypassing just the check for
/webtech in the referring string. Therefore a check is also made to
ensure that there are no
.. in the referring string. (Thanks to Rick S. for pointing this one out...)
Now has come the time to view the source for
PrintPage.asp (finally!). Upon inspection I think you'll agree that
it is quite simple (it was that way be design!). Without further fuss, here is the code!