“CodeIgniter lets you write kick ass PHP programs”

At work, I have been lucky enough to work directly with Luis Majano, the author of an awesome Object Oriented Framework for ColdFusuion, ColdBox (I have blogged about it before)

Using the Coldbox Frame work really took my CF coding to the next level.

At home, I am not lucky enough to have access to a Coldfusion server. I run everything off of a dedicated PHP machine that I have had for some time now. Mostly due to the cost of the CF licenses, and the investments I have already made in the running so many sites in PHP.

After using ColdBox, I wanted to find something similar that would really help me write better code, and do it more quickly. I first looked at cake and wasn’t that excited about it, it seemed more complicated then it should be.

After doing some more research, I came across Code Igniter. Code Igniter has turned my PHP world upside down. Its easy to use, straight forward, and has a lot of build in functionality that would take me forever to achieve on my own.

Working in an object oriented frame work just makes me feel like a more effective programmer for some reason. Maybe its because I feel more organized and can really see how fast I can put applications together using it.

The user guide, video tutorials, wiki, and forums for code igniter all rock. There is a wealth of information in there that I can draw off of.

I am re-working notpopular.com 2.0 once again (at this point maybe i should call it notpop 2.5), and I am using Code Igniter to do it. Lets hope that my newly peaked interest in object oriented PHP development will carry me though the development and launch of notpop 2.0 (2.5?!)

Amazon S3 + PHP = Awesome image hosting solution

Recently I have been looking for a solution to allow users of notpopular.com to have photo albums of unlimited size. Its a popular trend in social networks, and its way cooler then the 5 tiny images that are allowed on notPopular.com (1.0)

There are many technical problems that associated with having this kind of open system. One of the biggest problems is storage (disk space), and load on the web server. Each image takes up space on the hard drives, and requires attention from the web server when an image is requested, taking attention and CPU from other more important processes.

After looking at several options, I came across Amazon S3 (Simple Storage Service). Amazon S3 is an online storage web service offered by Amazon Web Services. It provides unlimited storage through a simple web services interface. Data can be easily stored and retrieved at any time, from anywhere on the web. Amazon charges in proportion to the amount of data stored and applies charges for sending and receiving data. A perfect solution for what I’m looking to do!

S3 would store the data, and would handle the load of the requests coming from users, allowing my web server to focus on more important tasks like PHP processing and MySQL queries.

Here is the price break down for amazon S3 usage:

  • Storage
    • $0.15 per GB-Month of storage used
  • Data Transfer
    • $0.10 per GB – all data transfer in
    • $0.18 per GB – first 10 TB / month data transfer out
    • $0.16 per GB – next 40 TB / month data transfer out
    • $0.13 per GB – data transfer out / month over 50 TB
    • $0.01 per 1,000 PUT or LIST requests
    • $0.01 per 10,000 GET and all other requests

Using the calculator tool they have, and looking at the notpop data and projected traffic, my monthly costs would be around $20 a month, and even if things doubled in time, it would still only be $40 a month. Very reasonable for the speed and reliability that a company like Amazon offers.

I found some great php classes to work with S3, particilarly one from Geoffrey P. Gaudreault over at neurofuzzy.net

I am also planing on using some CNAME records on the notPop server to mask the amazon URL. Should be easy to do.

Last night I started to sew Amazon S3 into the pending notPop 2.0 code base. I will make some follow up posts about how it goes once I really start using it.

cfdump in php!

At work, I write ColdFusion, at home I write PHP. I bounce back and forth between worlds. Jack of all trades, master of none I guess.

One thing that I have always loved about ColdFusion is the cfdump tag. You feed it any variable, and it will spit out whats in it. Struct, String, Array, Query, Object, XML, it doesnt matter, it just works. I would go as far to say that its one of the best native debugging resources I have ever seen in a web development language.

In PHP, you can do a print_r() and look at the source, but that is no where as cool as cfdump. I have longed for a cfdump style resource to be available in PHP. Today I got my wish when I stumbled upon “dBug”. http://dbug.ospinto.com

dBug is a small PHP class that duplicates the cfdump tag from ColdFusion

look how simple it is to use:

include_once("dBug.php");
new dBug($myVariable);

The output looks like this:
phpdump.gif

dBug will handle anything you throw at it, just like cfdump does. This is going to help me so much in the future. If you develop in PHP, I think that this class is a must have in your tool kit.

dBug is free! get it today from http://dbug.ospinto.com

Using PHP and Math To slow down spammers

If you read my blog, you might have noticed a LOT of spam in the comments of the posts. I was getting 100+ a day. Getting you blog on the front page of Digg.com will do that I guess. I got tired of all the spam, so I had the server email me a copy if the comment to my T-mobile MDA phone, If I saw the post was spam, I could kill it right away. This got old because I was getting an email every 5 – 10 minutes, way more then I cared to check.

I know that captcha systems help with keeping spam robots out, but at the same time I find them hard to use so I didnt want to put one up. Also, many spam bots look for captchas and can read them now! I thought there had to an easy way to handle the problem.

Step 1
Rename the file that your form posts to. This will break many of the bots and help cut the spam for a little while.

Step 2
Using some simple php, I decided to make users answer a very simple random math problem before their post could be saved. Here is some sample code on how I set it all up.

click the thumbnail images for a larger view of the code

form.php
form.gif

process.php
process.gif

I realize that there are most likely better ways to solve this problem, like having the random numbers be displayed in images that are dynamically generated, and I will do that If this menthod fails. For right now it seems to be working. I hope that it works for you.

DOWNLOAD THE SOURCE CODE