Skip to content

PHP mistakes, misconceptions, bad practices and blatant no nos.

Link To Full Story: www.sellmix.com

4: Do not trust your users!

90% of beginner PHP programmers trust their users. I may have completely made that statistic up – but I’m pretty sure it would be close enough to that figure. Sure, the majority of the people who will use your web application will be nice people who would never dream of damaging your website. However, all it takes is one a!*hole with enough knowledge about web applications to ruin the entire show. If you’re asking the user to enter a number, check that what they entered is actually a number. If you’re asking a user to enter their email address, check to make sure that what they entered was actually an email address.

5: Brackets – use them.

if($condition)
      //do something

The above piece of code may work etc, but it makes your code far less readable. Instead, you should always try to use full parenthesis:

if($condition){
     //do something
}

It just makes your code easier on the eye and gives it some structure, that’s all.

6 – The often liberal assignment of variables onto one another

When you are constantly assigning variables onto one another, you’re not only using up memory – you’re also making it difficult to track any bugs that might pop up:

require_once("inc/vars.php");
$tax_insurance = $total_tax;
$cost = $tax_insurance + $other_variable;
$another_cost = $cost + $other_variable;
$cost = $another_cost;
$goddamit = $another_cost;

Ugh.

Gojko Adzic » Designing applications for cloud deployment

Link To Full Story: gojko.net

During the last two years, I was involved in several projects deployed on the Amazon cloud. Being a relatively early adopter was a fantastic experience that provided lots of opportunities to burn my fingers and learn from mistakes. It also seriously challenged my view of scalable software architectures. I spoke about key lessons learned at CloudCamp London last week – here is the summary of that presentation.

Before I start, I’d like to point out that judging from this post it might seem that I have a negative view of cloud deployments, but nothing could be further from the truth. I have many nice things to say about the cloud, but lots of other presenters at CloudCamp do that all the time. I wanted to play the devil’s advocate a bit and expose some of the things that you won’t necessarily find in marketing materials.

First fundamental rule of cloud deployment: No single machine on the cloud is going to be any more reliable than any other machine there

Before the cloud, I was used to investing more in machines which were more important. Database boxes would have better power supplies than web servers, ideally redundant. Content servers got better disks and lots of them. A nice Cisco appliance would balance requests to web servers, and was infinitely more reliable than them. Web servers, for all I cared, could crash and burn at any time, as long as they did not all decide to do it at the same time. With the cloud, this isn’t possible. No matter how many virtual cores or memory you rent, all the boxes are running on very similar hardware. Or, putting it in another way:

Get started with CodeIgniter | Papermashup.com

Link To Full Story: papermashup.com

I’ve never really got the hang of PHP frameworks and have tended to use my own custom built CMS but even with this I still find myself writing the same code over and over again. In the past I’ve dabbled with CakePHP and the Zend Framework and not really got very far, so a few days ago I downloaded CodeIgniter. Although I’m extremely new to this I was pretty blown away by the simplicity of setting things up and getting an actual webpage that processes something online.

How It Works

CodeIgniter uses the MVC or Model View Controller architectural pattern, if your not familiar with MVC it is a logical object orientated development approach. below we look at a simple example of how we use the MVC.

mvc

Subversion 1.6.9 Released

Link To Full Story: subversion.wandisco.com

Yesterday, the Subversion development community released Subversion 1.6.9, the latest patch release in the 1.6 series.  Subversion 1.6.9 contains several bug fixes, some of which include:

  • Support for Berkeley DB 4.8.
  • Reduce errors when committing to an out-of-date pass-through proxy.
  • Fix a couple of segmentation faults, one in FSFS, the other when using "svn resolve".
  • "Future-proofing" the 1.6.x release line by allowing 1.6.9 to notice when the current working copy was created by a 1.7-era Subversion client.

The complete list of changes can be found in the change log.

An Interview with David Walsh | Nettuts+

Link To Full Story: net.tutsplus.com

How and why did you first get involved with web development?

I taught myself HTML, JavaScript, and CSS during my Freshman year of high school. I don't recall why I fell in love with web programming but I simply couldn't stop myself from tinkering, tinkering, tinkering. Ten years later I'm still obsessed with web programming and pushing each web language to its limits.

Are you currently working for any development companies or are you freelancing full time now?

I have a normal 8-5 day job but I enjoy my few hours after work the most. It generally gives me time to take the problems encountered during the day and turn them into blog posts. My opportunities to experiment at work are limited so the freedom to tinker I enjoy after work is refreshing.

On many of your websites, you mention Wynq Web Labs. Can you tells us more about Wynq and the role you have in it?

Wynq Web Labs is my consulting / freelance arm. Wynq specializes in taking your vanilla website to the next level using MooTools or jQuery. So much can be done using those (or any) javascript libraries that there's always room to improve a basic or advanced website.

Open Sourcing Google Wave Notifier

Link To Full Story: Danny Tuppeny

Yesterday I finally got around to do something I've been planning on doing for a number of weeks. I uploaded Google Wave Notifier to Google Code. From today, Google Wave Notifier is Open Source!

In hindsight, I should have done this much sooner. The app is now very stable and contains all the features that I planned to implement (and more!). I'm still getting lots of feature requests, and I really wish I could implement them all. However, in reality, I just don't have time. By sharing the code with the world, all of these features need not go unimplemented!

I still intend to work through bugs and some feature requests myself, though it's unlikely to be at the rate of previous releases. With help from the community, hopefully we'll still see regular releases and new functionality.

For more info, or to download the source, please visit the Google Wave Notifier page on Google Code.

How BuddyPoke Scales on Facebook Using Google App Engine

Link To Full Story: High Scalability

How do you scale a viral Facebook app that has skyrocketed to a mind boggling 65 million installs (the population of France)? That's the fortunate problem BuddyPoke co-founder Dave Westwood has and he talked about his solution at Wednesday's Facebook Meetup. Slides for the complete talk are here. For those not quite sure what BuddyPoke is, it's a social network application that lets users show their mood, hug, kiss, and poke their friends through on-line avatars.

In many ways BuddyPoke is the quintessentially modern web application. It thrives off the energy of social network driven ecosystems. Game play mechanics, viral loops, and creative monetization strategies are all part of if its everyday conceptualization. It mashes together different technologies, not in a dark Frankensteining sort of way, but in a smart way that gets the most bang for the buck. Part of it runs on Facebook servers (free). Part of it runs on flash in a browser (free). Part of it runs on a storage cloud (higher cost). And part of runs on a Platform as a Service environment (that's GAE) (low cost). It also integrates tightly with other services like PayPal (a slice). Real $$$ are made selling virtual goods like gold coins redeemable in pokes. User's can also have their avatars made into dolls, t-shirts, and a whole army of other Zazzle powered gifts.

I Have No Talent // RailsTips by John Nunemaker

Link To Full Story: railstips.org

The other day someone sent me an IM and thanked me for my open source contributions. They then said something about wishing they had my gem/code creation talents. I didn’t miss a beat and informed them that I have no talent.

It is true. I have no talent. What I do have is a lot of practice. And I am not talking about occasionally dabbling in Ruby on the weekends. I am talking about the kind of practice where I beat code that isn’t working into submission (though often times the code wins).

The kind of practice where all of a sudden I realize that it is 2am and I’m exhausted physically so I should go to bed, but mentally I feel on fire so I let the code have me for another hour or two (I imagine this state to be like a marathon runner or ironman near the end of their race).

Wait till I come! » How I build my data.gov.uk mashup – UK-House-Prices.com

Link To Full Story: www.wait-till-i.com

UK-House-Prices.com is a web site to see how the prices in a certain area changed over the years using a data set released by the UK government as part of the data.gov.uk initiative.

Here’s a screencast showing the app:

The first step was to get the right data. I was lucky enough to be invited to the initial “hack day” and pre-release of the data and looked around for something to mash up. Initially I wanted to do something with environmental data but I found a lot of it to be very old. Therefore I just did a search for “2009″ at data.gov.uk and found that the house prices data from 1996 to now in England and Wales is available. The plan was set. This was it:

  • I wanted to build an interface to show this information that was very fast, very portable and show a nice map of the area next to the numbers.
  • I wanted to build this as a web app and as an application for the Yahoo homepage (as I needed to build one as a demo anyways)
  • Traffic and speed was the most important issue – as this might get huge.

Code: Flickr Developer Blog » People in Photos: The API Methods

Link To Full Story: code.flickr.com

First off, we have a simple accessor method which will return you a list of people for a given photo. It’s called flickr.photos.people.getList, and it takes a photo ID as its sole argument.

But what about the reverse – finding all the photos of a given person? Fret not, that’s why we have flickr.people.getPhotosOf. This method takes a user ID, and since it returns a Standard Photos Response, you can also specify any extra data you want through the extras parameter.

Sometimes, simply consuming data isn’t enough – you will feel a need to create some. If you want to add a person to a photo, simply use flickr.photos.people.add. This method takes a photo_id and a user_id, and can optionally take another 4 arguments (person_x, person_y, person_w, person_h) to specify a “face boundary” for that person.

If you decide you don’t like the face boundary later, there’s always flickr.photos.people.deleteCoords to remove it entirely, or flickr.photos.people.editCoords to update.

Last, but not least, you can remove someone from a photo with flickr.photos.people.delete.

Obviously, all of the above methods require that the calling user is permitted to perform the action in question.