PHP mCrypt blowfish interop with Java, .NET

by justin carlson on 07/20/2010
PHPWhile writing a PHP ePayment client for USBank's service, I noticed strings that were blowfish encrypted with PHP's mCrypt in ecb mode were not matching the encrypted values from Java and .NET. This was frustrating as the Java client was not using any specific settings for block size or pad type, and, sorry guys, Java documentation seems lacking.  Luckily the solution was very simple.

Download Census.gov Tiger/Line shape files (2009 Edition)

by justin carlson on 12/21/2009
PHPUse the php script or wget example to pull down census.gov Tiger/Line shape files. It would be easier to just use wget, but I'm using windows.

PHP COM() Access to Microsoft Word

by justin carlson on 12/11/2009
PHPIn this article you will find very basic sample code for accessing Microsoft Word using PHP and COM(). This sample includes a table and some alignment settings.

PHP COM() access to Outlook Calendar

by justin carlson on 12/11/2009
PHPIn this article you will find sample code for accessing Microsoft Outlook Calendar events using PHP and COM(). This sample includes recurring events and was tested on Windows XP with Outlook 2003.

PHP DOMNode::removeChild, Whitespace

by justin carlson on 11/05/2009
PHPJust a quick note to remind myself later. DOMNode::removeChild leaves whitespace unless you tell it not via:
$document->preserveWhiteSpace = false;

How Do I? Get the file location an object class was defined in PHP.

by justin carlson on 03/10/2009
PHPFirst time I've needed ReflectionClass. Just making a note for future reference.  This will give you the pull path and filename to the file that defined the class for any given object. Requires PHP5 (OO).
// abstract class foo extends bar {}
$object = new foo();
$class = new ReflectionClass(get_class($object));
echo $class->getFilename();

SSL Peer Verification with cURL

by justin carlson on 01/25/2009
PHPThere are too many posts on the web advising people to turn off cURL peer verification to disable the "Error performing HTTP request: error setting certificate verify locations" or "Error performing HTTP request: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" messages. Please stop turning SSL_VERIFYPEER off.

PHP SQL Tokenizer and Parser Class

by justin carlson on 10/16/2008
PHP

Coffee Break Code - Quick ExamplesI like to use a pagination class I wrote for lots of projects, it takes a sql query, and some configuration options, and puts together a flexy compatible paged data grid, and can serve CSV and XML Excel dumps of the data. It's handy as hell and makes my life simple. Someday I'd like to merge it and an ajax enabled version into one class and release it but for now I am just writing about the sql tokenizer component.

I couldn't find a sql tokenizer for php, or a parser of any kind.  If there's one out there that I didn't see hopefully someone will let me know.

Updated 12/29/2008 - Found a complex query that didn't play nice, so I tweaked the code.
Updated 01/16/2009 - Found a bug, fixed it.
Updated 01/27/2009 - Changed from GPL to LGPL
Updated 02/25/2009 - Parse error, fixed it.
Updated 10/29/2009 - Inline comments fix.

CakePHP Behind a Reverse Proxy

by justin carlson on 09/25/2008
PHPI was asked to assist with the support of a website that uses CakePHP.  After tweaking the vhost entry and path config the site displayed as expected, but users were not able to logon.  "Authentication failed." was displayed when an invalid logon was used, but nothing happened when the correct credentials were passed.

Searching for information on Google yielded very little help, except one thread that discussed cake's security level settings.  I modified those settings (CAKE_SECURITY) by updating the app config's settings for Security.level in the code.  This did not make any difference.  Authentication was still not working, and the session was invalid.

Zend Debugger Crash from IE

by justin carlson on 09/18/2008
PHPI'm still trying to figure out the root cause of all this. But I will explain a workaround until then.

Problem: Apache crash / restart when accessing any local php app/site. Environment: WAMP install ZendDebugger.dll enabled via the ini.

PHP open_basedir Performance Benchmark

by justin carlson on 07/28/2008
PHPI noticed a much slower response time from a website I'm working on once I setup open_basedir in my php.ini so I decided to run some benchmarks. It seems like a generic page with several includes ( templates, etc ) takes 4x as long (0.15531941822597 off, 0.64727306365967 on)   to return with open_basedir on.  Sure there's going to be overhead, but I was surprised to go from 6 or 7 requests per second down to 2 just by enabling this.

So safe_mode sucks, and open_basedir is painful. Awesome.

Very Simple Twitter Examples

by justin carlson on 05/10/2008
PHPBoth Twitter and TinyURL are very easy to talk to using PHP. I've tossed together a few quick PHP examples to demonstrate the basics of connecting to twitter and posting tweets.  TinyURL's API is actually just a HTTP GET.  Combining the two makes a great way to attach script monitors to services, rss feeds, blog postings, etc. 

PHP5 safe_mode Restrictions

by justin carlson on 05/06/2008
PHPIt seems that safe_mode will continue to make some things downright painful.

I'm working up a test script to explain this better and test the environments I am forced to work with.

Here are some more similar yet different details:

    http://forums.devshed.com/php-development-5/mkdir-possible-under-safe-mode-78005.html

    http://bugs.php.net/bug.php?id=33639

    Related? http://www.titov.net/safemodepatch/

It may be that all I need is for safe_mode_gid to be enabled in the php.ini

I don't have access to the environment in question to see if it's already on/off or if the admin will even enable it.  This is all fallout from PCI Compliance requirements.

PHP, Performance and Timezones

by justin carlson on 03/02/2008
PHPEvery call to a date/time function will generate a *E_NOTICE* if the time zone is not valid, and/or a *E_STRICT* message if using the system settings or the TZ environment variable.

It doesn't matter what your error_reporting is set to, the notice is generated whether it is displayed or not. So if you're working with a batch process, CLI script, or Propel, you had better set your timezone in your php.ini file and/or your config.php for the site or application you are working with.

Zend Debugger Is Free

by justin carlson on 09/06/2007
PHPYou can download the Zend Debugger without buying a Zend product.  According to  IBM "Several open source clients can interoperate with the Zend Debugger", I've only used phpEclipse and Zend so that's all I can confirm.  Every time I have to rebuild a PC (usually a co-workers but this week it was mine), I end up Googling for this info and the debugger url, so I've decided to store it on my site.  It's old news, hopefully everyone's been doing this for awhile.