Building a Site With Clean URLs

As an aside in my post about Cambrian House I posted some code for making pretty URLs. A few people (no, not CH) have asked for a little more info, so I've written up an explanation of that code.

PHP makes it very easy to create bad URLs like /member.php?id=8. Those are bad because web spiders don't like to crawl URLs with GET variables, some browsers don't cache any GET URLs, they expose that you use PHP (when the visitor should never even know), and they're just downright ugly and hard to remember. I'm going to present a way to build a PHP/Apache site with clean URLs.

Let's look, line-by-line, at the contents of .htaccess. While writing this article I found a more elegant equivalent in the Wordpress code, so I'll present that here:

# Tell Apache to load mod_rewrite.
RewriteEngine On
# Rewrite URLs for the location starting at /
# Note this is URL location, not a path to your web root.
RewriteBase /

From PHP to Perl

In recent months I've been moving away from PHP, a language for which I have developed in for 6 years. I learned it because it was free instead of learning ASP. I made a website for my boyfriend so he could write articles about computer gaming hardware. I interned at a place and did PHP, and then moved to another company doing PHP.

I was pretty content with PHP ... until I saw Ruby first, then made friends with some Perl geeks, realized they weren't all arrogant l33t language snobs and took another look at Perl. Hey, its kind fun! PHP had become boring and Ruby and Perl gave me a new challenge. At first, I only read them thinking "how can I do this in PHP.." and managed to get my company where I did PHP to send me to YAPC. But after a time, I realized I didn't like PHP anymore and I wanted to do Perl or Ruby.

I've written a few articles on CodeSnipers on the differences between Ruby and PHP. I wrote one on datatypes in PHP vs Perl. Click on the Ruby topic on the side to find those articles.

Since I have been coerced into giving a 5 min talk at Perl meeting tonight about this.. Here's some of my thoughts in a blog...

Why the Light Has Gone Out on LAMP

menion writes to tell us that Cliff Wells has an editorial calling into focus some of the perceived problems with LAMP. Wells calls PHP and MySQL this generation's BASIC citing the Free Online Dictionary of Computing: "BASIC has become the leading cause of brain-damage in proto-hackers. This is another case (like Pascal) of the cascading lossage that happens when a language deliberately designed as an educational toy gets taken too seriously. A novice can write short BASIC programs (on the order of 10-20 lines) very easily; writing anything longer is (a) very painful, and (b) encourages bad habits that will make it harder to use more powerful languages well. This wouldn't be so bad if historical accidents hadn't made BASIC so common on low-end micros. As it is, it ruins thousands of potential wizards a year."

Reason to like PHP?


print { open my $out, ">", "pidfile"; $out or die } $$, "\n";

Ruby;'pidfile', 'w+'){ |fh| fh.puts }

I could have used ‘$$’ instead of, but I prefer readability


file_put_contents( 'pidfile', getmypid() );

Yeah I know, I know but anyway…

This article provided by

Ruby on Rails makes nice with PearDB

Another exciting day in the life of a PHP -- > ROR programmer..

Last week I wrote about how Ruby could access a PHP session and how php site structure could fit inside a Rails structure. This week, I share my findings on how to get ActiveRecord to work with our existing PearDB sequence tables. These are my random, scattered meanderings on a solution..

If you haven't used Pear's DB class before, it creates a table with the [tablename]_seq for each table and stores a single row with a single column "id" with the value of the last ID used. Example of use. This was designed so that your code could easily port to other databases that didn’t have autoincrement like MySQL. Whether this is a good practice is not up for debate, I have what I have :)

Ruby on Rails makes nice with PHP

Not all projects can jump ship from a home grown PHP site to Rails, especially projects where there are exactly 1.3 programmers for the project. I was surprised there wasn't much information on integrating php and rails site (spare me the flame wars). All new development will be done in Rails and old PHP will be written in Rails as time permits. I was exploring some of the ways that this could be possible and what possible problems might arise.

I will need to read certain sessions variables from PHP into Rails, I will not need to write to the session. I found a ruby script PHP Serialize which takes a php serialized string and converts it to a Ruby datatype. If your sessions are stored as files, they are in /tmp/sess_[session id] where session id stored in $PHPSESSID they contain a special serialized string. Ruby can get the session id from the cookie and read the file, and PHP Serialize will convert it into an object. If your sessions are stored in a database, then of course you'll be able to create a Rails model to access it. If you need to write to a php session, then I think it would be better this way. I didn't try using sessions stored in a database, because I use files. I’m not sure how you would do it stored in memory. In any case, reading from the session file I believe is a temporary hack at best.

Perl & HTML Generation

There are probably vast amounts of documentation and tutorials about the Perl CGI Module but readers of this site who are not Perl programmers probably won't go out on a whim and read about this interesting module. Even a PHP programmer might get inspired ... is a "Simple Common Gateway Interface Class." I'm still learning myself how to use it, so I'll share what I know..

CGI can be used with two types of programming styles, functional and OOP. So far I've only used the functional.

Include the module with

use CGI qw/:standard/;

Here I'm bringing the "standard" set of functions into my scope. From my limited understanding thus far, the qw thingy delcares what to "export" into the local scope. Anyways, thats what I'm going on now until I become reach monkhood and earn my Camel Pin.

As always when learning something new, I start Uber Simple. Inspired by a exercise in Practical Perl Programing, I created a form that will take hourly rate, hours, overtime and spit out the salary.

DC PHP Conference - Announcement and Call for Papers

PHP in the Federal Enterprise and the World:  Secure Solutions for Federal Agencies, IT Companies and Non-Profit Organizations

We are hosting the first DC Metropolitan area PHP Conference this October.  Not only that, but since we're in a unique location with opportunities and potential impact like nowhere else in the world, we're taking a slightly different look at PHP. Our mission is to demonstrate and teach how PHP is a solid, sensible, cost-effective, and low risk development language to use for government and non profits.

Therefore, our Presentation Tracks fall into four areas:

  • Integrating PHP with Federal Operations and the Enterprise
  • Security & Accountability
  • The Art of PHP
  • The Business Case for PHP

The Call for Papers ends on July 7th and gives suggested topics in each of these areas.  Your presentation will be up to 400 people including decision makers for some of the largest and most influential organizations in the world.

PHP can be cool like Ruby

All the cool kids these days are using Ruby...however I am stuck in a PHP world at the moment. I've been doing Ruby on some side projects and its got me thinking in a ruby mindset...and I wonder.. can PHP do that? And I've found a few things that might make a PHP geek's life a bit easier or at least PHP a little more tolerable.

Yes yes, the good old for loop.

for ($i = 1, $i <= 10; $i++) {
    print "Processing $<br>";

The simple act of doing something 10 times. Ugly huh? He's one way to do it in Ruby..

Versioning - The Next Big Thing

In the web development world, anyways. So, in the grand scheme of things, maybe not a huge deal to anyone else. Versioning is going to be one of the biggest problems and opportunities there is in web development, and it's going to take us at least five years to get it right.

Actually, let me admit up front that five years is a shot in the dark, and optimistic to boot. If people keep hanging out with bondage and discipline languages like Java and C# that are still catching up to language and framework developments from the 90's it'll take us more like ten years. (Attention Lisp Weenies: Yes, I know you solved every problem forty years ago for certain values of "solved" and "problem" while the rest of us were getting work done.) Not only is versioning a difficult technical problem, it will be difficult to educate programmers in what it is, how it works, and why you'll wish you used about a year after you decided it was too much work.