PHP Lesson 1: Pretty URLs!

I am going to start a new practice here. Every now and again I’m going to post some PHP code with some explanation. Today, I’m going to write about what I’ve been calling “pretty URLs” and how to create and manage them in PHP.

PHP includes a variable in the superglobal scope $_SERVER called “PATH_INFO.” PATH_INFO includes information entered after the name of the requested script.

Let’s use firsttube.com as an example. The URL of a story is constructed as such:

http://firsttube.com/read.php/[id]/[url_friendly_title].html

The story is also accessible as /read.php?id=[id]

So how do we construct this so-called “pretty URL?” Using PATH_INFO. Read on for details.
Continue reading

Linky see, linky do.

More links assembled from the annals of the browser history of AS.

Goodbye Microsoft, Pete has now left the building
A fellow Floridian, an Microsoft insider, describes why he finally ditched Microsoft and Windows for Apple and Ruby-on-Rails. For the record, I still think Rails is a fad. It’s very cool, but the catch is, ya gotta learn Ruby to use it. A lot of these frameworks are very powerful and great RAD tools, but I’m sticking with PHP5 for now.

Do NOT watch this
*Suriously*. It’ll make you dizzy, and you’ll feel a hollowness in your stomach. I don’t usually get queezy, this is the worst video I’ve seen in ages. Yikes.

“We Have Not Forgotten, Mr. President.”
Keith Olberman tears President Bush a new arse.

Asshat flies out of truck
Truck + Dunes + Guy being douche-bag = ?

Why Vista will be the end of Microsoft
Of course, we all know it won’t be. On the contrary, it will be a success. But I agree, it will certainly be the first chipping of the wall. Start the timer. Microsoft’s dominance will be majorly altered in the next decade.

MobileQuo

Eugenia released a little web-let called “MobileQuo” the other day, and it caught my eye. I downloaded it and hacked it up and made some changes.

1. This version is more secure – it won’t let the content of the feed break your HTML. Update: Apparently, the desired behavior is to render the HTML, not to preserve the markup as markup, so the new version Eugenia has released reflects that change. So code will be rendered, including javascript, so beware!!
2. This version outputs friendly errors. The 1.0 version can fail if your php.ini isn’t set up right, or output a blank page if there are certain errors.
3. This version is more portable and doesn’t rely on a particular PHP configuration.
4. Most differently, this version can cache the results. This way, each reload won’t hammer an RSS feed. Rather, the results can be cached for a perdiod and fed from cache, and then when the cache expires, it reloads the cache.

The source code is here: MobileQuo. Note that you will need to upload a blank WRITABLE file in your MobileQuo directory. Then just use the rest of the code from Eugenia here.

Last post

This is my last post before the wedding. I’m officially off the osnews-crew list until I get back, I’m done with everything online, I’m setting up my “out of office” stuff. But before I go, here’s a list of fun links.

First up, what happened to Hostess Chocodiles? Chocodiles were essentially chocolate covered white-cake Twinkies. They used to be on sale everywhere when I was a kid, but now I can’t find them. Enter freshchocodiles.com, who will gladly ship you a 10-box for a measley $9. I’m all over this when I get back.

There’s a script I want to check out called Links Thumbnails, which does the Yahoo!-like website thumbnail when you hover over a link. Look for that here soon.

Well, that’s all for now. See you all in a week and a half.

General Update n Shit.

Well, the big news is that Jenn and I got our marriage license today. So, 37 days to go, and we are now legal to tie the knot. Woohoo! She’s currently typing away on her iBook (wishing for a Macbook, btw), telling people about the updates I made to paleyscheinberg.com last night. It’s a simple site I built with iWeb, but it’s very easy, and takes a HELL of a lot less time than writing PHP. It’s static, but simple.

That said, I’ve been writing all sorts of fun things lately. I’ve been really doing a lot of javascript work – tons of AJAX stuff and a lot of script.aculo.us and prototype code. I fixed several behaviors in the Galaxy code, but only applied them to /staff so far. Ultimately, it’s a nice looking app and behaves really well. The next step is adding a few new features:

1. The ability to purge last fetch time, for testing purposes.
2. Turn off feed fetch time update in fetch.php (not in autofetch.php).
3. Add a newer & older link to the bottom of the page.
4. Potentially, add links to add comments to the native blog.

I got a new book today which I’m going to be reviewing for OSNews called Object Oriented PHP from No Starch Press. So far, so good.

I’m about to take a stab at the new comments template for OSNews version 4. It is going to include some additional information, like registered date, average score, and number of posts. This might help people decide who they should trust more.

MagpieRSS Bug Fixed

The “Galaxy” code I wrote for OSGalaxy has now been ported over to the OSNews Staff Blog section, and there’s a crappy bug. When an RSS feed has more than one category (a legal setup), Magpie concatenates them into one word.

So, I’ve written an elementary, temporary workaround for the multiple categories problem with Magpie. Essentially, rather than concatonating the categories, this script will use only the last entry in the RSS/Atom feed. It’s pretty basic, but it’s tested on PHP4 and PHP5 and it doesn’t change much code.

To use it, just save this file as rss_parse.inc and replace it in your magpie install. It’s based off of 0.7a, which is from the latest release of Magpie at this time, 0.72. You can find the code at http://firsttube.com/s/rss_parse.inc.phps.

SQLite

Today I built and ran my first successful SQLite queries. It’s really easy, but the damn phpsqlitetadmin tool I was using never worked right. Finally I tried a new program and it worked like a charm. I didn’t realize SQLite supported views, triggers, and custom functions. That’s kinda cool.

Of course, what will I actually use SQLite for? I use MySQL and that seems to work everywhere. The onyl place SQLite seems to be useful is for installations that don’t support databases, and in that case, you have to hope they have SQLite installed or are using PHP5. Perhaps I’ll write the next version of tihs weblog for SQLite and just say you need PHP5 for it to work.