MozTips
- On Mozilla and Open Source Software
Recently Commented:
Previous Next

Posted on October 02, 2006 by jay_sheth2. Edited: October 03, 2006 by jay_sheth2.

Adding Basic HTTP Authentication to XML-RPC Class From Zend Framework

Ever since Zend came out with their PHP 5 framework a year or so ago (or was it further back than that?), I've been wanting to try it out. I've been stuck in PHP-4-land for so long. PHP 4 had been oodles of fun, and an extremely useful tool - yet I kept doing things like buying Adam Trachtenberg's Upgrading to PHP 5 book, or reading articles on Sitepoint about new features in PHP 5. I think back now, and Adam's book was published in July of 2004 - 2004! Where did the last two years go?
While 2006 is mostly a blur, the excitement of PHP 5 is still fresh and crisp in my mind.

After hearing Nate Abele trash the Zend Framework at last week's NYPHP meeting, I felt a strange urge to go out and try it for myself. It reminded me of the School of Visual Arts's recent Subway campaign: "How bad do you want to be good?", except it was more like "How bad do you want to be bad?". "Very baaad!" was my answer. After hearing how it was "the Windows Vista of the PHP world" (I know I got that quote wrong, but it was something to that effect) I wanted to see what this bad-boy framework was all about.

I read through the online documentation, and came across the XML-RPC package. I wanted to try it out with an XML-RPC app I'd build more than a year ago, but it did not have any methods to support basic HTTP Authentication, which this app needed.

I did a bit of research, and a bit of coding, and here's my result:
http://www.moztips.com/code/zendfw/xmlrpc/Client_src.php

In case you're wondering what I changed:
I added the _username and _password class variables, I added the setCredentials() method, and I modified the _sendRequest function to supply the right 'Authorization' header in case a username was set.

I did a basic test, and it worked. Hooray! Let me know if it works for you too.

PS: If I keep up the rate I'm updating this site, you can expect another entry next March! (Just kidding - I plan to update it more often.)


Category: PHP

Comment: Read 14 comment(s)

Link: Permanent Link