Tips from the Windows Pros: Scripting for Interactive Sites


As I said earlier in the chapter, the idea of using programs to generate Web pages on-the-fly was the real spark that turned the Internet into a global phenomenon.

The original server-side programs were complex and difficult to write and debug, however, until bright people developed scripting languages for Web servers. Scripting systems put most of the complex stuff into one program that was provided with the Web server. Then, users could write short, easy to manage programs, or scripts, that leverage the power in the main program to do all sorts of interesting and interactive things.

The most common scripting language is Perl, which is very popular in the Unix and Linux world. Perl can be added to IIS so that you can take advantage of the huge pool of already-written Perl programs that are available for free on the Internet. If you know Perl or want to learn, you can download a free Windows version at www.activestate.com. These folks give away Windows versions of Python and TCL as well, two other popular scripting programs, and have a huge library of documentation and free scripts.

Microsoft came up with a scripting system called ASP, which stands for Active Server Pages. (Everything at Microsoft was "Active-something-or-other" for a while there. Now it's .NET this and .NET that.) You can choose what programming language you want use inside: the default is a dialect of Visual Basic, but you can also use JavaScript, Perl, or other languages, if you install the appropriate interpreter programs.

The cool thing about ASP is that you can mix HTML and your chosen script language in the same file. You can use HTML to manage the formatting and static part of the page, and scripting to generate the dynamic part, and it's all there in one place.

ASP scripts can take full advantage of Microsoft COM and ActiveX programming objects. These objects provide a way for scripts to perform very complex functions such as manipulating databases and sending email. You can find loads of useful pre-written ASP scripts on the Internet. For example, check out www.asp-pro.com and click on "ASP" on the left-hand side. Also, take a look at Microsoft's Developer's Web site at msdn.microsoft.com/code and on the left side select Code Samples by Topic, ASP.

As an example of what ASP scripting can do, use Notepad to create a file named time.asp in c:\inetpub\wwwroot, with this inside:

 <HTML> <HEAD> <TITLE>What time is it?</TITLE> </head> <BODY> You viewed this web page at <% response.write time() %>, <% response.write date() %>. </BODY> </HTML> 

Then you can view http://localhost/time.asp in Internet Explorer.

Here's what's happening: IIS copies most of the file literally. But stuff in between <% and %> is treated as script code, which are commands written in Visual Basic or JavaScript. In this case, VBScript commands insert the time and date into the HTML file at the server, before it's sent to your browser. To see what I mean, right-click the displayed page in Internet Explorer and select View Source. You'll see what the ASP script generated and send to you.

CAUTION

There are dozens of Web sites that have libraries of scripts that you can download and use. Be very careful when you use a script obtained from these sources. Remember, scripts run as programs on your computer, and can do a lot of damage if they're poorly written or have nefarious stuff built in. For example, several widely used but poorly written scripts that are used to send the contents of HTML forms via email can easily be exploited by spammers to send any message they want to anybody they want. You could find one day that your computer had spent the last week or so sending a few million Herbal Viagra ads. The recipients of those emails won't be happy with you. So, do your research and check out the bug history and credibility of any script you download.




Special Edition Using Microsoft Windows XP Professional
Special Edition Using Microsoft Windows XP Professional (3rd Edition)
ISBN: 0789732807
EAN: 2147483647
Year: 2003
Pages: 450

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net