10 Powerful PEAR Packages, Page 2
6. Enforcing Coding Standards with CodeSniffer
Returning to the previously discussed matter of following coding standards (see the section introducing PHP_Beautifier), it seems that this task is akin to writing documentation: most developers will avoid it at all costs. Unfortunately, the costs of avoiding either can be pretty high, resulting in lost time and increased maintenance costs. While no known solution can force you or your colleagues to write documentation (although phpDocumentor will certainly help), you might be able to improve upon the adoption of coding standards using PHP_CodeSniffer.
7. Fooling Spammers with Text_CAPTCHA
The Completely Automated Public Turing Test to tell Computers and Humans Apart, or CAPTCHA, is an ingeniously simple solution for preventing automated spambots from littering your website's blog comments and other forms with unwanted advertising. Relying on the fact that computers are notoriously bad at certain tasks -- such as notably recognizing the contents of an image -- programmers require humans to respond to a simple challenge in order to successfully submit a form. Such a challenge would include asking the human to echo the contents of a programmatically generated image containing a random string, such as
If you're sick of deleting unwanted comment spam and would like to integrate CAPTCHA protection into your forms, check out Text_CAPTCHA. Text_CAPTCHA will generate the image-based text and text field for you, storing the text value in a session variable that you can check once the form has been submitted. If the text field matches the session variable contents, chances are the submitter is human. Otherwise, you can disregard the form.
8. Managing Git Repositories with VersionControl_Git
I'm an avid GitHub user, relying upon the service to manage not only my various software projects, but also my books. I've even gone so far as to integrate Git-driven features into recent projects, which allows me to easily view a project's contents without having to use the command-line or login to GitHub.com. Although GitHub offers an API for talking to the service, I'd rather avoid writing my own PHP implementation and instead found VersionControl_Git, a simple object-oriented interface to my local repositories.
Although still a work in progress, VersionControl_Git is already capable of performing the most commonplace repository-related tasks, such as creating a new repository, viewing commit information, and reviewing repository contents.
9. Tweeting with Services_Twitter
To paraphrase the ancient riddle, "If you didn't Tweet about it, did it ever really happen?" If you're adamant about letting the world know about every cup of coffee drank, newspaper article read, and previously lost sock found, check out Services_Twitter, a convenient PEAR package that can send updates to your Twitter account. All you need to do is authenticate using your Twitter account's username and password, and pass along an update using the package's
update() method. Using this simple yet effective package, all of your applications can be sending updates to followers in no time.
10. Validating User Input with Validate
Validating user input is difficult, which explains why so many websites are compromised due to the developer's avoidance of this tedious task. Yet there's no excuses for neglecting to validate all user input, because any task that is simultaneously so difficult yet ubiquitous is likely to have been implemented in a PEAR package. Sure enough, the powerful Validate package has been around for some time now, making input validation a breeze.
The Validate package covers basic validation tasks, including validation of numbers, email addresses, and URLs. Locale-specific packages such as Validate_US provide validation tasks specific to the United States, offering validators for phone numbers, zip codes and social security numbers. See the Validate documentation for a complete list of locale-specific validation packages.
About the Author
Jason Gilmore is the founder of the publishing, training and consulting firm WJGilmore.com. He also is the author of several popular books, including "Easy PHP Websites with the Zend Framework", "Easy PayPal with PHP", and "Beginning PHP and MySQL, Fourth Edition". Follow him on Twitter at @wjgilmore.
Page 2 of 2