Archive for the ‘php’ Category

Modifying Wordpress Rewrite Rules - small problem + solution

Wednesday, September 3rd, 2008

add_filter('rewrite_rules_array','yourawesomefunction');

I had to look at the Wordpress core code to work this out - thought I was going nuts. If you apply new rewrite rules using the rewrite_rules_array filter you need to ensure that you refresh the rewrite rules that Wordpress has stored in a hidden option. You do this by simply resaving the Permalink Structure under the Options menu in the admin area of your WP install.

Not immediately obvious that this would be required, but makes sense that they generate the rules and store them at this point.

Implementing Free Geolocation with PHP Using Maxmind’s GeoLite Country

Sunday, August 17th, 2008

Need to serve up different content for people from different countries? Or track users by country? Or make a site more usable by providing options relevant to a particular country? I recently had a small programming task which required pre-selection of a country field based on the visitor’s country.

Maxmind offers a free Geolocation database, GeoLite Country which allows lookup of country from an IP. They claim it to be 99.3% accurate. They have a paid version that is more accurate. They also offer other databases, including one to lookup a city from an IP. The database is available as CSV data or in binary format. The binary format is very easy to implement as they provide APIs in a variety of languages. I used their PHP API. There are code samples to get things going quickly.

I used their PHP class which was the easiest to implement. Simply upload the class file and binary file and require the class file. The calls are simple and the lookup is fast. Very easy to implement.

Amazon’s Seller Central SOAP API

Tuesday, July 15th, 2008

Very disappointing experience working with Amazon.com’s Seller Central APIs. Their documentation is frankly very bad. Undocumented and incorrectly documented aspects will make the curve to get this working unnecassarily steep. Their support is not responsive. The forums are not overly helpful although you can see similar issues coming up. Disappointing for such a large and groundbreaking web-based company, especially as they are looking to promote their Web Services infrastructure to developers.

The comments in this article are very accurate of my thoughts/experience implementing Amazon’s Seller Central SOAP API using PHP (they are using Java) …

My time getting to the ‘hello world’ stage on this interface was measured in days vs minutes for pretty much every other system I have worked with.

Good notes on implementing Amazon’s Seller Central SOAP API

That article should help anyone regardless of the particular language they are using to do this. It helped me with one important final aspect that was undocumented by Amazon.

For more specific notes on doing this with PHP check out the last chapter of this book …

The Web Developer’s Guide To Amazon E-Commerce Service

A couple of key things in there will overcome issues with the particular way the Amazon SOAP server works. There will still be problems - but that will get you much of the way.

Note: don’t waste your time with Amazon AIM. As the article above mentions, unless you have an old account migrated from Amazon’s Marketplace system it will only work to download reports - it will not allow adding or updating products.

Great Article on Unicode and Character Sets

Wednesday, June 18th, 2008

It is easier as a developer who deals with English 99.9% of the time to overlook this stuff - especially in PHP - until you open and try to manipulate a bunch of .txt file not even thinking about the variety of Unicode formats. Found this rather enlightening …

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

Good for any PHP coder to read, especially as the documentation on this stuff at PHP.net is a bit on the lean side.

Update:Character Sets / Character Encoding Issues from WACT with lots of PHP-specific information.

Testing out OpenX - PHP-based Ad delivery

Tuesday, June 3rd, 2008

I have a couple of sites I want to run ads on and just installed open-source ad server, OpenX. The installation was easy. I plan to run the first tests here - so watch out!

I tried this out years ago as PHPAdsNew. New name and new product really. My first impressions are good. Will post how I go once I get into it some more.

Here is a walkthrough of setting up a campaign …

Generating Barcodes with PHP

Wednesday, May 14th, 2008
barcode example
see below for the translation of the barcode

PHP Classes is always my first stop when looking for PHP code, no matter how advanced (or easy to be honest).

I have recently been working on a shopping cart system and implementing barcode generation, as well as allowing a barcode scanner be used as an input device to speed up aspects of order management and data entry.

There are a number of barcode generation classes at PHP Classes. Harish Chauhan’s Barcode Class has been very useful. His class supports a number of barcode standards and allows generation at various sizes. There is a simple form provided to allow generation of barcodes and demonstrate the features of the class.

I will update this when I have finished all the functionality.

The barcode scanner arrives in the morning!

Oh - and the barcode above says “www.createwebsite.info” in the code128 format.

UPDATE: here it is with the font uploaded for the text!

a barcode example with the text embedded

Having problems importing a large MySQL database? Try this …

Saturday, April 19th, 2008

Bigdump is a PHP script that staggers the import of a large MySQL dump. It processes a small chunk and then refreshes. This continues until the database is fully imported. This is great for hosts that don’t give you access to ssh or who place restrictions on file uploads or server execution times.

The only thing to configure is the database host, user, and password. Simply upload the dump file to the same directory as the bigdump file (use FTP or the built-in uploader) and then process that file.

Reasons for switching back to PHP from Ruby on Rails - one perspective …

Sunday, March 23rd, 2008

Great article by the developer of CD Baby on changing back to PHP after working with Ruby on Rails. Not a diss on Rails - he just states several reasons why he found it easier to return to PHP. Good perspective.

read more | digg story

Save yourself some work: important PHP classes/libraries/projects for developers

Saturday, March 22nd, 2008

From sending mail with attachments to fetching content via RSS to sending a trackback - a list of common coding tasks that is solved with good existing code.

read more | digg story

One they didn’t mention and that I use all the time is Manuel Lemos’ HTTP Protocol Client - complete with lots of examples!

PHP and MySQL Optimization

Wednesday, March 19th, 2008

A list featuring a few very simple tips for optimizing php/mysql applications …

read more | digg story