Colorbox wrong height when first opened / scrollbars appear

Colorbox seems to have a strange issue – if it contains image(s), when opened for the first time, sometimes it opens with the wrong height set so scrollbars appear. I’m not sure what causes this, as in my case I had width and height properties set to all images AND the images I tested with were already loaded by the browser.

Solution / workaround: trigger resize after colorbox has loaded.

onComplete: function() {
    $.colorbox.resize();
},

Custom user data fields with WordPress Membership plugin

Here’s a quick overview of integrating custom user fields with Membership plugin (v2.0.7 at the time of writing).

Basically, we’ll have to:

  • Create some fields to be added after Membership’s own registration form
  • Create a function to validate and save the new registration form fields on submission
  • Copy-paste the whole user account edit form from Membership plugin and modify it to suit our needs
  • Create a function to override Membership’s own account edit form

Bulletproof* image upload security guide for developers

In the series of tubes there’s a ton of tutorials and guides on image upload security, but apparently still not enough –  I stumbled upon yet another PHP application image upload vulnerability. These are ridiculously easy to spot, take about 10 minutes to exploit and if the attackers succeed, odds are they will be able to upload a shell, execute arbitrary code on your server and do pretty much whatever they want. So if you’re a developer (especially PHP!) and don’t know how exactly image uploads should be implemented, please please please take the time to read and understand.

Continue reading

Becoming a better developer

Learn something new with every project. If necessary, take some unbilled extra time and figure out how to do something better than in your last project. Your client will be happy and you will become better, faster and stronger.

Have a personal wiki, or share one with your team. Document stuff. Save code snippets. You can thank me later.

If you get stuck with a problem, write a blog post about it. Traffic Helping out other people is always good, and it will leave a good impression of you for potential future employers.

Seek out a mentor online. Hackerbuddy is a great place to start. PHP Mentoring is another place to consider. I’m an autodidact and I know you can learn everything by yourself, but learning from more experienced or smarter people than you can save you a lot of time.

How to remove scrollbars from Facebook iframe tab

Facebook iframe tabs have a fixed height of 800px, which is really annoying as longer content means scrollbars will appear. After a couple of hours of googling (I tested a whole bunch of different solutions and nothing worked for some reason), this is how I finally solved the issue. Note that it’s a band-aid fix, but I’d rather not delve into the insides of Facebook application development to figure out what’s really going on.

Continue reading

Why you should be using a proper HTML sanitization library

The idea that it’s easy to protect your web app from XSS seems to be floating around the interwebz. I’ve seen a whole bunch of “tutorials” saying stuff like “just use htmlencode()” etc.

If you’re building web applications, even small ones, do yourself a favor and use a proper html sanitization library. I hear good things about HTMLPurifier (PHP) and Sanitize (Ruby); there probably is a library for most other languages as well. I don’t dare to recommend anything specific so you’ll need to do some research, but it will be time well spent. And if you’re using a framework or CMS, use the sanitization functions they provide.

Continue reading