Beernink.com Home | Books | Articles | Postcards | Hikes | Weblog  
Air is water with holes in it.
 
Saturday
8 May
2004

Another stylistic advance, that makes no difference whatsoever! When you're building pages dynamically using PHP (or any other language), you end up with URLs that look like this:

	articles/showpage.php?page=1234.html

This works just fine, but it's a bit unsightly: it reveals what's going on behind the scenes, and is hard to remember. I recently started using mod_rewrite to clean this up quite a bit. Mod_rewrite is an Apache module that takes an incoming URL, and remaps it to something else. There's a lot you can do with it, but I just wanted to give this brief example. My web host has mod_rewrite enabled by default, so it was trivial for me to use it.

	RewriteEngine on
	RewriteRule articles/(.*)\.htm$ articles/showpage.php?page=$1.htm

Friday
26 March
2004

I just discovered a new *free* piece of software called JAlbum, which can be used for creating photo albums. It's quite easy to use, although the interface is completely form driven. You point it at a folder of images, you point it at a destination folder, then you say "Build Album". It generates all the thumbnails and medium sized images automatically, and spits out some HTML pages for inclusion in your site. With one additional click you're previewing your photo album!

The form interface includes a number of different "skins" which are used to select the appearance you want, and there are a number of additional parameters you can set: the number of thumbnail images, the sizes of thumbnails and images, and so on.

And best of all, in each skin folder is a set of template files that are used to build the page: one for the list of thumbnails, one for the frameset used to display them, one for displaying images, and one for the blank page that is displayed when it first opens. You can tweak these so that your photo album matches your site perfectly. It only took me a couple of hours to figure it out and make it look like the rest of my site.

I did discover one important thing, though. In the Advanced section of the program, there's an option for "High quality scaling". After turning this on and increasing the "JPEG quality" to 80%, my image quality improved dramatically, with very little increase in image size. I did notice that building the album took longer, though.

My current album is not quite ready for prime time, but I'll post a link when it is.


Thursday
8 Dec
2003

In PHP, it is easy to access the properties of an object by name, if you know the correct magic formula. I was unable to find this specifically documented anywhere, which is why I'm describing it here.

Assume you have a person object that has properties for name, age, and height. Normally, you would access them using:

	  $name = $person->name;
	  $age = $person->age;
	  $height = $person->height;

But let's say somebody was selecting the property from a form, and you wanted to use the selector to get the property. In this case you could access the property like this:

	  $property = 'name';
	  $name = $person->{$property};

Of course, for a nice clean object-oriented implementation you'd want to wrap this in an accessor like this:

	  function get_property($propertyName) {
	  	return $this->{$propertyName};
	  }

Of course you could achieve the same results by putting all the properties that need to be accessed into an associative array, but this is much more fun, isn't it?


Saturday
15 Nov
2003

Had some Scrabble-playing friends over for dinner last night. They left us a kind thank-you note:


Thursday
11 Nov
2003

Back at work on Beernink.com again!! Over the last week or so, I've added a book review section and a couple of articles. In particular, I've made a major pass over almost everything, cleaning things up and making them consistent throughout the site.

Below I mentioned that I might revert to my old table-based design rather than using pure CSS. I have done that. My headers are all table-based, because it is simple, and works everywhere. But the content of my pages is purely CSS (at least on the pages I have converted).

I arrived at a simple style for using CSS, which I believe will work everywhere. I have separate style-sheets, for modularity, but I use PHP to load them. Like this:

<style>
    <?php include 'style/std.css'; ?>
    <?php include 'style/blog.css'; ?>
</style>

Now, for each section of the site, I load the main styles from std.css, then I load the section-specific styles from a separate file, xxx.css. All browsers see this as a single inline style record, yet it allows me to modularize and share styles.

And since the articles are split out, the content of a simple page might look like this:

	<?php include 'inc/header.htm'; ?>
	<?php include 'inc/joke.htm'; ?>
	<?php include 'inc/emptynav.htm'; ?>
	<?php include 'reviews/pages/farmer.htm'; ?>
	<?php include 'inc/footer.htm'; ?>

Without using any PHP other than the include statement, you can make your site a lot cleaner! Note that these includes all depend on the include trick I described in the article below.


Tuesday
17 Dec
2002

Today I figured out how to do PHP includes in a portable way. I wanted to be able to include a file, say /inc/header.inc from any of my files. Unfortunately, includes are not relative to the document root, but are taken from a place on the include_path, which makes sense for things like libraries. I don't want to modify php.ini, because that would be shared by all domains, which isn't what I want. So the solution is to get the document root for the current document, and add that to the include_path. One remaining gotcha is that the separator character for Unix differs from the separator character for Windows. Here's what I ended up with:

<?php ini_set( "include_path",              		/* set include_path */
               ini_get("include_path") .    		/* get old value */
               ((PHP_OS == "WINNT")? ";" : ":") .	/* add separator */
               $_SERVER["DOCUMENT_ROOT"]        	/* add document root */
               );
?>
      

I just add this little beauty to the start of my php files, and then I can simply include the desired files, as in "include 'inc/header.inc'".

Another note: A few days ago I complained about the fact that MS Dev Studio doesn't know what to do with .php files, which disables all the nice features for writing HTML. My workaround for that is to tell Apache to send all .html files to PHP. Here's what I put into my .htaccess file:

	AddType application/x-httpd-php .php .html
	Action application/x-httpd-php "/php/php.exe"
      

For files that don't use PHP, I use the .htm suffix. The other nice benefit of this method is that all my files look like html files -- I don't know why, but all these .php, .jsp, and .asp suffixes look a little nerdy to me... Or maybe I just don't like showing off.


Monday
16 Dec
2002

Finally got my copy of Programming PHP! It's an excellent overview of the language including examples of how you would use it to accomplish many common tasks. It's a tribute to the simplicity of PHP that the full language reference, with examples, and comprehensive function summary, fits into less than 500 pages -- compare to Programming Perl, which is over 1000 pages, and much denser.

Not to go into too much detail, but Perl has variables, arrays and hashes, each with its own magic symbol ($variable, @array and %hash); PHP has $variables (which can be arrays or hashes), and arrays and hashes are the same. Perl has arrays and lists, which are only subtly different; PHP has arrays, which can do most of the things lists can do. I'm starting to understand why PHP is so popular.

Now that I actually know what the code is doing, I can go back and redo my PHP from last week. First on the list is to really use includes to separate out the shared pieces.


Friday
13 Dec
2002

It's Friday the 13th!

It is amazing what mysteries reading the manual can solve! After configuring my php.ini file yesterday, I now find that mail is correctly sent from the contact page on my local machine -- I don't understand why. I also discovered the register_globals variable, which controls whether or not your GET and POST params (among others) are automatically imported into your environment. The default for new versions of PHP is off, but all the examples on the Web assume that it is on. This explains one of my problems a couple of days ago. I also discovered that you can use $_REQUEST("paramName") and it will look in $_GET, $_POST, and $_COOKIES for the desired value.


Thursday
12 Dec
2002

A short day, with all the Christmas activities afoot. I tried php.ini-dist this time instead of php.ini-recommended. That worked much better for me since error logging to the browser is enabled. I went through all the options and customized it for my environment, and I think everything is set up correctly. Functions are now working within my page, but I haven't yet tried including any of the modules.

Also created a main page for articles, that works like the postcards index. This generally worked well, but I discovered that I have some pages that are using my old style sheets, and other pages that are using the new style sheets, and of course I can't include two modules that require different style sheets into the same page (or it would be messy). Eventually I'm going to have to come up with one universal style that works anywhere.


Wednesday
11 Dec
2002

Jumping recklessly onto the PHP bandwagon, I decided to spend my time today writing a page of PHP code. I figured writing an email form for my contact page would be just the ticket. And it was.

Building the form was easy. Reading the parameters from the POST request was easy too. Making the form entries "sticky" was a little trickier -- I still don't have the text area quite right. And validation of the fields wasn't too hard either. So why did it take as long as it did?

I never got mail to send from my local machine, although it works from my web host. I didn't even have a php.ini file set up!! And when I switched to the default one, I stopped getting error messages. And I kept forgetting the $ in front of variable names, which causes strange and subtle bugs. I tried to borrow some form validation code, but I couldn't get functions to work -- I got an error message every time I tried. So I just kept it simple.

And despite the problems, I got it working, and I'm happy with the results. Give it a try.

Also whipped out a quick technology survey for Apache, MySQL, and PHP. It's sort-of a glorified about page.


Tuesday
10 Dec
2002

Today I restructured Postcards from Nepal and Postcards from New Zealand using PHP as a modularization tool, as described in this article.

The main index file for each (index.php) uses PHP to create an array of menu names, an array of titles, and an array of files containing the content. The desired page is passed in as a parameter. The page number is then used to display the page's title and content, to hilight the current page in the menu, and to create the next/previous page links. Much nicer that the SSI hack I tried a few days ago.

By parameterizing everything, all my layout is in a single file, so that the importance of simplifying everything with style sheets decreases. Best of all, I did index.php for New Zealand first, then simply copied it to the Nepal folder, redid the entries in the three arrays, and it worked!

So far the only drawback is that by naming my main files "index.php", I lose the HTML syntax hilighting and code hints that MS Dev Studio provides, and it doesn't help with PHP either. Time to find a new editing environment...


Monday
9 Dec
2002

Installed PHP on my Windows box. So now I have it running in all the environments I use. So far I have Apache, SSI, MySQL, PHP and Perl running everywhere, so all my pages run everywhere.


Friday
6 Dec
2002

Read some good CSS articles last night. One talked about laying out columns in a way I hadn't tried before. I tried doing the layout as described in these articles (using margin-left: 20% instead of float: left), and it solved the problem I was having on Mac IE with the text block occasionally wrapping to the next line.

I then took a look at the page using Navigator for the first time. Not a pretty sight. I rebuilt my header line using line-height to specify the height, instead of using padding to try to center the text vertically. That works pretty well.

But at this point, I'm not sure that CSS is ready for prime-time yet. I may switch back to my table-based layout soon.


Thursday
5 Dec
2002

Rebuilt the styles for sections and sidebars, one element at a time. Creating a complex style sheet is much easier if you first create a simple version of your elements, each with a different background color. I now have something that works reasonably well on both Mac and Windows (IE only so far).


Wednesday
4 Dec
2002

I like to keep a record of what I've done and when I've done it. When I'm on a consulting job, I keep careful notes of tasks and durations. However, when I'm doing stuff for my own website, I'm not so careful. The answer, of course, is to keep a daily log of my activities -- and there's nothing that screams third millenium quite like a weblog.

Ok, so that forces me to admit that all the entries below this one were forged, reconstructed, reconstituted from the merest whisps of historical evidence. I admit it, I wrote them all in one sitting.

And then I viewed the pages on my Mac -- I guess style sheets aren't as portable as I hoped... Or to put it another way, some browsers are more forgiving than others.


Tuesday
3 Dec
2002

Rewrote my home page using CSS for everything. The length of the home page went from 304 lines of HTML (as formatted by MS Dev Studio), to 168. As desired, I removed virtually all layout information from the page -- it now only contains an outline of the functionality -- and all layout is now done in the style sheet. It's a thing of beauty... Take a look

Fortunately I had Dynamic HTML: The Definitive Reference handy, which has some decent sections on CSS. Not exactly a cookbook, but at 1000 pages, who has room for examples?  (The second edition has 1500 pages -- let me guess... he added 500 pages of examples...).


Monday
2 Dec
2002

After putting the shared menu into a single file, I then decided to try to hilight the link to the current page in the menu to show what page you're on. SSI can tell you the name of the current page, and it has a conditional statement. So I modified the menu to hilight the current page. I'm not happy with the look yet, and it slowed down the page a lot, but it works. The first gotcha was that since the menu page itself needed to use SSI, I had to change it from a .txt file to a .shtml file. The second gotcha was that MS Dev Studio doesn't seem to know about .shtml (or chooses not to know), so I lose all syntax hilighting in .shtml files (which would be most of them). So I added an .htaccess file that tells Apache to look at .html files for SSI directives too, which made MS Dev Studio. This solution also works on my web host, so everything is working acceptably now. The only problem is that I still don't really like the way the menu hilighting works.

"Discovered" CSS! The page from NN/g that I used as the basis for my home page makes moderate use of style sheets to ensure a consistent look across the site. As I'm interested in anything that can make building web sites easier, I realized that this was an important thing to learn. I found quite a nice site for learning about CSS. Check out their CSS Guide and their CSS Gallery.


Sunday
1 Dec
2002

I wanted to experiment with modularizing my pages, so I took the list of pages from my Nepal journal (a menu down the left of the page), and saved it in a text file. Then I used server side includes to load that page into each page that needs it. Works fairly well. Now I can update the menu in one place, and it will be used everywhere.


Saturday
30 Nov
2002

Signed up to become an Amazon affiliate tonight. I hope to do book reviews in the future, and virtually everything I do involves some sort of reference book (no jokes please), so adding links to books is a very natural thing.

And guess what.... They'll pay you 5%-15% of the revenue from any item someone buys after linking to Amazon from your site. Why, if dozens of people buy books through me every month, it could pay my web hosting fees!

By the way, I'm reading The Book on the Bookshelf right now, and recently finished Summerland. Check them out!


Tuesday
25 Nov
2002

Wrote a lengthy resume today. A potential client requested a resume, and never having written a proper one, I decided that it was worth spending a day working on it. Print preview shows it at 7 pages -- is that too long?

One website I looked at said that a resume should generally be limited to one or two pages, but that if you are a consultant, more is better -- go figure. After discussing with my wife, we decided that I should do a short version with hyperlinks to the long version -- isn't the web great! 


Monday
24 Nov
2002

Wrote an article about how to select a web host. It's not quite done yet, but I hope to finish it soon.


Friday
22 Nov
2002

Converted my site to use the NN/g look. I started with their style sheet and home page, and then stripped out all their content, and put in my own content. I spent most of my time doing the actual conversion, and very little work customizing it for my needs. That will come as I develop more content.

Also, I have been looking for a good tool for site creation. I've been pretty happy with TextPad for HTML, and JCreator for Java, but I suddenly realized that I have MS Developer Studio on my machine (it opened when I tried to view a style sheet). I played around with it a bit, and realized that it is far superior to anything I have been using. So MS Dev Studio is now my editor of choice for HTML and CSS.


Thursday
21 Nov
2002

I was looking around the web for a clean and simple design for my home page. When I saw the NN/g home page, I realized that it was organized in a way that would support my site quite well. And since it is utterly devoid of graphics, it also matches my level of graphical skill and my lack of desire to make a flashy graphical site.

Of course I had looked at their site in the past, since I had worked with Bruce (and Don) at Apple, and since my wife is in the same field as those folks.  At the time my reaction was that it was very unusual for UI people to have or want a site so lacking in pizzazz, flair, and panache.  But now that it comes to implementing it myself, the simplicity makes a lot of sense.


Oct-Nov
2002
I opened my account with IMHosted on 10/27/2002.

  • Enabled portals, BBS, chatroom etc that come with site (10/29)
  • Had epiphany about similar web hosting environments (11/1)
  • Figured out how to work SSH (11/4)
  • Turned home.beernink.com into smaller modules that could be developed locally (11/20)
  • Recovered beernink.com from crashed Mac server (11/19)
  • Got beernink.com working locally and deployed (11/20)