Issue 72 * June 4 2009

I was a poet, and didn't know it
Or, how I discovered I was a server scripter after all

By Bill Marriott

I have some confessions to make. While I was really caught up with the introduction of the Web and learned HTML (it wasn't that hard, and I leaned a lot on programs like FrontPage and Dreamweaver), I never put the effort into learning the popular server language PHP. The syntax was byzantine and unforgiving. I'm not someone who considers Notepad.exe an "IDE." And my brain refuses to memorize stuff like "print date ('g:I a l F j');" - for some reason it just doesn't seem to fit.

Honestly, I experienced similar feelings about the old Revolution CGI engine. Yes, I put the time into learning how to install it and configure it, but the way I had to output Web pages was harrowing and it only took a few dozen "500 Internal Server" errors (bugs in my scripts) to discourage me with that experiment.

As a consequence, I looked down on the very concept of server scripting as something I really didn’t need to do, that it wasn’t worthwhile. Such is simple human psychology that we denigrate the things we don't comprehend. 

Server Scripting Books
Books about server scripting gathering dust on my bookshelf.

Getting turned on-Rev

My first moments with on-Rev changed my thinking about server scripting forever. I had that same “aha” moment I had with HyperCard. Back then, I thought, “Oh! So I could write software with this?” and immediately began to do so. Same thing with on-Rev today. What took me ages to figure out – with books on scripting cluttering up my physical desktop, and browser windows with Google searches on syntax and solutions cluttering up my virtual one – now  came easily and naturally. “Oh!” I said to myself. “So I could write server scripts with this!”

Once I allowed myself to truly believe that I could write scripts on the server, doors opened for me. I started to imagine how I would set up a login system for my consulting clients on my work site, and family members on my personal one. How I would code the photo gallery I had always envisioned. Simple front-ends for multi-user databases, and forms to send email (instead of putting my email address out for spam-harvesting bots).

I could present a different layout theme if they visited me in the morning versus afternoon. I could optimize a list of downloads so the Mac version of one of my Rev standalones was at the top if they came from a Mac. So many possibilities opened up for me to create enticing, attractive sites for myself and clients. I could now consider taking on projects I would have turned down before.

Most importantly, I found myself feeling that elusive sense of fascination with programming that is the source of all great ideas.

Later in this article, I’m going to share with you a script I wrote in just the first day of using on-Rev… but let me explain why this product is so very different from my previous forays into server scripting: 

  • Of course the biggest one is that it uses Revolution, a language I already know and love! But the big breakthrough here over the old CGI engine is that I can use “code snippets.” What that really means is that instead of having to put the HTML inside of my script, my script goes inside of the HTML. That’s better because there’s usually a lot more HTML code than Rev code in a page, and I don’t have to worry as much about handling quotation marks within quotation marks and other annoyances like calculating how big my page would be before I displayed it, etc. I write less code, spend less time on tedious stuff, and it’s easier to follow.  Trust me, it makes all the difference in the world.
     
  • The second godsend is I have a nice script editor that colorizes my syntax and helps me manage the files on the server. I don't have to mess around with a text editor and FTP client. I no longer bite my fingernails over line endings, and I don't need to remember to set file permissions. Several steps are now consolidated into a single click, and it is simply bulletproof.
     
  • The third really cool thing is when I screw up my script, which I often do, I can put in a breakpoint, just like in the Rev IDE, and see what's wrong, using a true debugger. I can step through my scripts line-by-line, and I can inspect all the variables to see where I've messed up. This was a real pain in the neck in the past. I would be completely lost before, looking through a glass dimly; now I have some clues, face-to-face with my syntax errors.
     
  • Finally, and this is something I really appreciate, it's all pre-configured and ready-to-go. The old Rev CGI required me to download the Linux build of Revolution, locate and extract the right files, upload them to the server in the magic spot, set the permissions, and even then it didn't work with some of my Web hosts! Writing to their tech support was usually a waste of time. With on-Rev, it's just double-click and I'm ready to go.

The on-Rev client application I've just been raving about is still in pre-release status, but already it's incredibly useful. Since the service launched, there have been two updates, and the improvements keep coming. The latest version, just released, adds some more customization abilities, further simplifications to the upload/download process, better code formatting, and more. Here's a look at the new preferences panel:

New on-Rev client offers active FTP, more customization options

New monthly and annual plans

While I'm talking about recent "developments," now might be a good time to mention that the "Founders" period has ended and on-Rev is now available with affordable monthly and annual plans. The list price of on-Rev is $25 monthly and $250 annually, but until the end of the month you can sign up for just $16.95/month or $169.50/year - and you lock in that rate for as long as you maintain your membership. (If you visit the store and notice the "retail" price doesn't exactly match what I just said, please indulge me. Because of limitations in our shopping cart, we had to adjust them slightly so the coupon code ONREVINTRO would work out to the proper end prices. Once that deal expires we'll reset them to the proper values.)

So, if you sign up under the annual plan, you're paying about $14/month for a great scripting experience. And if you want to dip your toes in the water and see what it's like, $16.95 is a pretty good price for trying that, since there's no setup fee with this coupon like there normally would be.

High-Performance Hosting

Now as I've mentioned the whole Rev server scripting side of this is in pre-release status, which means the on-Rev script editor and the language itself isn't feature-complete. We're going to be adding a lot more stuff before the official launch on September 1 at RunRevLive.09. But there's nothing pre-release about the conventional hosting side of things.

We went all out and picked some really nice hardware at a world-class data center, with plenty of fast, fat pipes connecting it to the rest of the Internet. There's an easy-to-use control panel that handles just about everything you'd want to do with the service, with all the one-click installs and goodies you'd expect from any other provider.

The on-Rev Control Panel. It's sure nice to see all those infinity symbols!

Of course you get a ton of storage and bandwidth, unlimited email addresses and domains, plus your own on-rev email address and sub-domain, so you don't have to own a domain or transfer one to on-Rev just to try it out. In short it's a great value in hosting, even if you never use the on-Rev stuff (but I know you will).

Rolling my sleeves up

The very first "real" thing (past the simple "Hello World" stuff) I wanted to do with on-Rev was a guest book. I can recall this being one of the first things I wanted to do with PHP, and I found stuff like this on the Web:

<?php
 if ($message != '') 
 {
  $message = str_replace ("\n","<br>",$message);
  $message = strip_tags ($message, '<br>');

  $newRow = '<div class="viewGuestbook">' . ($message) .
  	    '<br>' . date('d.m.Y H:i') . ' - ' . strip_tags ($name) .
  	    '</div>';
  	      
  $oldRows = join ('', file ('guestbook.txt') );
  $fileName = fopen ('guestbook.txt', 'w');
  fputs ($fileName, $newRow . chr(13) . chr(10) . $oldRows);
  fclose ($fileName);
 }
 
 include ("readbook.php");
?>

That's just one of three files the guy used to do his guest book example, and it doesn't include the part where there is a form to write the comments in. Yes, I could upload it and it worked, but I didn't really comprehend what was going on until I spent a lot of time working with it.

How was I going to handle things in Rev? Well I know I needed a form, so I mocked one up very quickly in an HTML editor:

<FORM METHOD="post" ACTION="???">
	Name:<BR>
	<INPUT TYPE="text" NAME="Name" SIZE="50"><BR>
	Comment:<BR>
	<TEXTAREA NAME="Comment" COLS="50" ROWS="10"></TEXTAREA><BR>
	<INPUT TYPE="submit" VALUE="Post Comment!" NAME="Submit">
</FORM>

Which gave me a form that looks like this:

Now, I had already used enough forms in the past to know that when the user clicked "Post Comment!" it was going to look for a server script by the name of "???" and send along three values: Name, Comment, and Submit.

I opened up the on-Rev editor, clicked the "+" icon to make a new file on the server ("ez-guest.irev"), and pasted the above code in, between the usual <HTML> and <BODY> tags. (yes, I know you don't have to capitalize tags anymore, what can I say, I'm old-school).

I clicked the save icon and then hit "View Online." Looks great.

Now, I want this form to appear below the existing guest comments. Which of course, there aren't any yet. I decided that I wanted to keep them in a simple text file for the time-being, so I made up another file, "comments.txt" and put in just a simple line of text as a starting point:

<P><H1>User Comments:</H1></P>

I saved that and returned to my script. I wondered, "would this work?" as I typed the following ahead of the form:

<?rev put url "file:comments.txt" ?>

Sure enough, I had the big heading showing up just fine. Rev took the contents of the comments.txt file and just slipped it into the stream of HTML that would be output to the browser.

Now to make it interactive. The "???" had to be replaced with the name of the script file that would handle the input. That PHP guy made three files... But why not make it one file, the same file being used for the form?

If someone comes to this page just browsing, there won't be any "input" but if they've clicked "Post Comment!" then there will be stuff within the Name field. How I express this for on-Rev is as follows:

if $_POST["Name"] is not empty then
   -- Do something
end if

Now, "$_POST" is simply a variable on the server, named to be consistent with other programming languages like PHP, that holds the contents of whatever the user has entered into their form. It's an array, with each key (element) of the array being named after the fields in the form we just received.

In later versions of on-Rev, the $_POST business will have a friendlier synonym and more English-like syntax as well. But for now, $_POST[ fieldname ] is easy enough to use and remember.

So, if there is some information in the Name field, it means we're coming to this page after someone has submitted a comment. I need to add that comment to the existing ones before I display the form at the bottom. So I just update my If statement to put those comments at the end of the comments.txt file... My script now reads:

if $_POST["Name"] is not empty then
	put "<p><b>" & $_POST["Name"] & "</b></p>" & return \
		after URL "file:comments.txt"
	put "<p><i>" & $_POST["Comment"] & "</i></p>" & return \
		after URL "file:comments.txt"
	put "<hr>" & return after URL "file:comments.txt"
end if

This simply appends the submitted values to the end of the comments.txt file with some very basic formatting.

It belongs in front of the code snippet that shows the existing comments, and it of course has to be inside the <?rev ... ?> tags. Plus I need to update the <FORM> tag so it points to the right file.

I also don't like the repeated references to "file:comments.txt" because if I change that later on I don't want to have to edit it four different places in my script, so I'll simplify the script by adding a line to put that filename into a variable.

Finally, I'd like to timestamp the entries.

My completed code now looks like:

<HTML><BODY>
<?rev
put "file:comments.txt" into theComments

if $_POST["Name"] is not empty then
	put "<p><FONT SIZE=1>" & the long date && the time & \
		"</FONT></P>" & return after URL theComments
	put "<p><b>" & $_POST["Name"] & "</b></p>" & return \
		after URL theComments
	put "<p><i>" & $_POST["Comment"] & "</i></p>" & return \
		after URL theComments
	put "<hr>" & return after URL theComments
end if

put URL theComments
?>

  <FORM METHOD="post" ACTION="ez-guest.irev">
	Name:<BR>
	<INPUT TYPE="text" NAME="Name" SIZE="50"><BR>
	Comment:<BR>
	<TEXTAREA NAME="Comment" COLS="50" ROWS="10"></TEXTAREA><BR>
	<INPUT TYPE="submit" VALUE="Post Comment!" NAME="submit">
  </FORM>
</BODY></HTML>

Not too bad, eh? I have basic guest book functionality using just a couple statements. And because it's so easy, I'll be able to add the necessary error-checking and security filtering (like preventing visitors from putting malicious text in there that will execute code) very easily.

You probably have a lot of ideas on how to customize this script for your own needs, and I really encourage you to try on-Rev so you can see for yourself how it works.

Users love it

We already have hundreds of people using on-Rev and we're getting enthusiastic feedback from them. Here are just a few pages from our users:

We think on-Rev and the server technology we're building with it will result in some phenomenal creations from our users. Because in the end, the best language for server scripting is the one you'll actually use and master.

About the Author

Bill Marriott is the Director of Marketing for Runtime Revolution Ltd. and a Revolution User.

Main Menu

What's New

on-Rev Subscriptions