Browsing articles in "Web Apps"

Easy, Beautiful Charts with Flot

May 22, 2011   //   by Mike McMurray   //   Code, Web Apps  //  No Comments

I’ve been looking for a free, open source chart library for a while and was struggling to find something that was good enough (and handled time series and missing data points well). For a long time I’ve been using Fusion Charts (FC) and Open Flash Chart (OFC) in any in-house work and those products are very good. But they’re Flash, a little slow and not supported by some popular mobile devices. I’ve also used pChart for some testing but it was fairly stale in development and being images, had no interaction.

The Flot JS library was something I’d seen a while back, but before I became comfortable with JS and jQuery. It does almost exactly what I want, is farily light-weight, extensible and easy to use. In a few hours last week I swapped out the FC code I had written for Overview and put in something almost half the size with Flot that created (in my view) a better product.

So I thought I might let others know what a nice, easy option Flot is with a little example. Beware this is not a fully working, copy and paste sort of example, it’s really just a chunk of generic code I pulled out. Read more >>

Debug PHP Function Calls

Feb 11, 2011   //   by Mike McMurray   //   Code, Web Apps  //  No Comments

Logging errors can be very helpful as your code base becomes huge. But sometime it’s still difficult to find out what’s calling the function that’s giving the error. Wouldn’t it be nice if there was a way to see how you’d got to that function?

Well of course there’s a way in PHPdebug_backtrace. Just add something similar in a suitable place in your code and you’ll be able to find what functions were called.

$trace=debug_backtrace();
$caller = $trace[1]['function'];
// or just dump all the info
var_dump($trace);

Using PHP exec() with IIS6

Oct 12, 2010   //   by Mike McMurray   //   Code, Sys Admin, Web Apps  //  No Comments

There are a few work arounds I’ve found since having to use PHP under IIS6 and Windows 2003. Every now and again I come across something that just doesn’t work the same way with this variation of web server, OS and PHP.

I needed to double-check the DNS hostname being reported from users on an internal website. Our DNS is a little scratchy when it comes to scavenging and keeping itself tidy, so often a DNS lookup of the client IP will give an incorrect name. This happens especially for laptops that hop off and on wireless APs.

So to compare against DNS (and because it’s an internal site) I thought to query the machines NetBIOS name with,

exec("nbtstat.exe -A 123.123.123.123",$r);

and that quickly fails with an error about “failing to fork”. Essentially this means, PHP can’t do what you want.

It boils down to file permissions. you need to run cmd.exe and nbtstat.exe with that single command. Both those files are secured against non-system users – probably rightly so too.

To resolve, just allow your IUSR_SERVER user to have read and execute permissions on both those files. Your exec() command should now be working.

REMEMBER: You are responsible for the security of your server. If you really don’t need to let programs run on your web server, then don’t.

Ignore Network Latency at Your Peril

Sep 19, 2010   //   by Mike McMurray   //   Interesting Stuff, Web Apps  //  No Comments

We all know developers need to consider a few things outside their own backyard. Things like hardware and the network affect software even if there’s not much that can be done to control them (even if you’re Apple). This is especially true for the network if you develop software for mobile devices.

So to help us all understand why the nuances of any network are important to all of us, Nic Wise has a good little blog post about what to keep in mind. It’s written in people language and not TCP layers, so we can all benefit from this one.

LDAP in PHP on IIS6

May 28, 2010   //   by Mike McMurray   //   Sys Admin, Web Apps  //  No Comments

If you’re struggling to get the LDAP extension to work in PHP and IIS6 then you may want to read on. In my situation both the web server and PHP were confirmed to be working fine and reading the correct php.ini. But even with the correct line enabled in the php.ini file, LDAP would refuse to show in phpinfo() output.

After some searching of my own, it turns out that IIS6 on Windows Server 2003 (possibly XP too) will not properly read the PATH variable. So if you add the path to your PHP directory to the end of PATH, the DLLs required are still not found. This looks to affect IIS6 specifically as filesystem calls to the same DLLs did find them.

The solution – add the path to your PHP install to the start or earlier in the PATH variable and restart IIS. In my experience you will now see the LDAP options appear in your phpinfo() output.

Outlook Hates Line Breaks

Jan 22, 2010   //   by Mike McMurray   //   Code, Web Apps  //  No Comments

If you’ve ever wondered why your plain text email message is randomly ignoring line breaks like \n or \r\n then you’re not alone. I regularly use PHPMailer to send off automated emails and usually in plain text to keep it simple.

What Outlook 2003 (and 2002 and 2007 versions apparently) likes to do is be super helpful and remove what it regards as extra line breaks. It won’t be consistent either within a single mail or across many but it will make the content difficult to read. What you thought would be new lines will now be joined up in places and it seems to happen more often the further through the content you go.

There don’t seem to be many fixes for this issue but there are a few work arounds to help out.

  1. Turn off this “feature” in Outlook in the Tools»Options menu. Honestly I’m not sure what use it is anyway. Unfortunately you’d have to do this on all the recipient’s computers.
  2. Use HTML in your email rather than plain text. Depending on your content and need for complete accuracy, perhaps more time than it’s worth.
  3. Add twice the number of line breaks where you currently have them. This seems to help but now your email is rather full of white space and may be more difficult to read.

Other than changing email clients, which is pretty unlikely, that’s about it. If you know of other options to try and get Outlook to not remove line breaks, please leave a comment below. This Microsoft KB article explains which versions of Outlook are affected http://support.microsoft.com/kb/287816.

MySQL Replication on Ubuntu with DRBD

Jan 15, 2010   //   by Mike McMurray   //   How-To, Sys Admin, Web Apps  //  5 Comments

I’ve been looking around for some easy and open-source ways to handle database replication for a handful of small but important MySQL databases. A few options were viable but usually included too many config changes for things like creating a new database. DRDB on a Linux server seems to be one of the fastest and easiest methods to handle database synchronisation for DR purposes, so this is the subject of this post. The content is a combination of two main sources from Mark Schoonover and the Ubuntu server guide and the gotchas I found along the way.

This post will show you how to create two MySQL servers that automatically replicate all their databases using DRBD. With Heartbeat installed on a third machine you’ll have basic fail over protection as well (we’ll do this in another post). Only one of the database servers will be active at any one time. Read more >>

Using a WordPress Page for your Main Site Content

Jan 4, 2010   //   by Mike McMurray   //   Blogging, Web Apps  //  No Comments

Official WordPress logoI thought I’d make more use of WordPress on wekadesign.co.nz since it’s very powerful and apparently was recently voted top PHP based CMS ahead of Joomla and many other top-notch products. It’s ease-of-use and interface are all excellent and the massive user base and huge number of plugins make it very attractive for almost any web publishing.

After moving the small amount of static WekaDesign content into Pages, I copied a couple of files (index.php and .htaccess) from my WordPress folder (./blog) into the site root, changed the settings in WordPress (Settings»General»Blog Address) and viola, anyone going to www.wekadesign.co.nz, now hits WordPress. Good. Step one done.

Now to change the default landing page to be a static Page rather than the blog. Just as easy, visit Settings»Reading in WordPress and change the Front Page Displays option to be your Page. Excellent, now everyone lands at the the WordPress version of my static content. But how do you now send people to your old default blog page? You can use http://www.yoursite.co.nz/2009/ to target certain groups of content by date or category if you have Permalinks setup, but I couldn’t find the way that WP builds the default blog page.

It’s not obvious, but that 2nd option in Settings»Reading holds the key. The Posts Page option is asking you to select an existing WP Page that will act as a placeholder and be that default blog page. So, if you haven’t already, create a new Page with a suitable name. The name is important as that’s the URL everyone will use and see for your blog. So if you call the Page “peanut butter”, your blog page will now be http://www.yoursite.co.nz/peanut-butter/. It doesn’t matter what the content of the Page holds as no one will ever see it.

There is a slight “gotcha” with the Page names, in that any name being reused will work, but WP will append it with an incrementing number e.g. “peanut-butter-2″.

To finish off, just create a nice link on your site somewhere like the Sidebar to your default blog page.

New Version of Kisimi Wiki is Available

Oct 27, 2009   //   by Mike McMurray   //   Code, Web Apps  //  No Comments

I’m happy to announce that a new version of Weka Design’s free wiki software called Kisimi is available. There are a huge number of improvements in the 20091025 release. Here are some of the more important ones.

  • Page security allows you to dictate exactly who can view and edit your pages. Some people can edit your pages, some can view and everyone else can’t see a thing. Security is as finely grained as you want it to be.
  • Kisimi now comes with an upgrade option at installation time and things are a little smarter. Installation can take less than 2 minutes!
  • Longer pages with headings can automatically generate a table of contents section.
  • Users can specify a timezone so that the dates and times are relevant to their location.
  • Administrators can prevent new user sign ups. Handy for those sites publishing their documentation and support pages to the world.
  • Any user with an email address listed at www.gravatar.com has their avatar image appear in their preferences.
  • Tidier user interface with plenty of little shiny bits.
  • Plenty of bug fixes including those messages for PHP configs that show all warnings. It’s still recommnended that PHP is configured without warnings for production servers.

Just head to http://kisimi.wekadesign.co.nz to download the latest version and start managing your online wiki content better.

Adding up Rows with JQuery

Feb 26, 2009   //   by Mike McMurray   //   Code, Web Apps  //  No Comments

Simple and sometimes unnecessary function to add table cells together and populate another with the total. Using jQuery because its easy and it works and we all love it.

$(document).ready(function() {
    var x = 0;
    $("td.num").each(function() {
        x += parseInt($(this).html());
    })
    $("td#total").html(x);
});

Where your table cells to add up are <td class=”num”> and the table cell that has the total is <td id=”total”>.

Pages:123»