Main

March 19, 2011

Learning from others mistakes - move configs out of your boot loader

I'm a keen believer of learning from other folks mistakes and attempting to not repeat them. Source code disclosure and even worse configuration disclosure which happened with tumblr. One thing to remember, if you keep your configuration for your app outside your webroot, you reduce the chances of you actually accidentally disclosing your configuration. Typically one could even do something like:


<?php
require_once dirname(dirname(__FILE__)) . '/bootstrap.php';


Rather than having everything in your index.php file. Separating your configuration directives out to a separate configuration file outside the webroot and modifying that when making changes.

One can use your version control pre commit scripts to check that you've not borked a the file - checking for php scripts being of a file type php script vs file is one way of doing this - foo.php contains a php script starting with "i?php" and bar.php has same code starting with "

$ file foo.php 
foo.php: PHP script text
$ file bar.php 
bar.php: ASCII text

February 22, 2009

No Smarty

If you've not heard about it yet, there is now a website advocating not using Smarty. The time for using smarty has gone - but makes one wonder if Flickr, Facebook, etc. are still using it.

August 9, 2008

So long and thank you for all the fish, PHP4

It's finally EOL time for PHP4 and they sneaked out a release of PHP 4.4.9 out a day later. Not too many changes to 4.4.9.

August 3, 2008

Grab PEAR via CVS is you need it

Quick note that the PEAR installer is missing (go-pear.org has expired and has been snapped up by some cybersquatters) and http://pear.php.net/go-pear renders a 404. So the current solution is to grab the go-pear install from CVS:


curl
"http://cvs.php.net/viewvc.cgi/pearweb/public_html/go-pear?revision=1.11
8&view=co" | php

Cool the pearweb crowd have fixed go-pear via http://pear.php.net/go-pear :)

March 27, 2008

PEAR on a Shared Host

So sometimes one needs a standalone version of PEAR. Check out the the instructions on how to do an Installation of a local PEAR copy on a shared host.

This is quite useful when you are forced into using a clueless shared host who only have the bare PEAR installation on their servers, and have not ever considered installing DB, Mail, Net_SMTP, etc. which lots of people use instead of reinventing the wheel with each project. The added bonus of having and using your own standalone installation of PEAR is that you're able to install and upgrade your own PEAR installation as your need arises.

January 22, 2007

Version controlled home directory?

Evert mentioned that he is keeping his home directory in subversion.

I tend to have two setups. A full and basic home directory. Version controlled using subversion. Previously I used CVS.

The basic gets checked out at webhosts, etc. which I use. The full gets checked out at work and basically ensures that i have some level of sanity with my shells. I'm using svk to do revision control with subversion.

What's in my version controlled home directory:

The only difference between the two currently is that the work one has a few extra directories setup. I tend to use svk for work.

January 6, 2007

PEAR::DB alike wrapper for PEAR::MDB2

Chatted to Lukas earlier today, and discovered that he has already done the hard work and created a PEAR::DB wrapper for PEAR::MDB2. So now is definitely a good time to look at upgrading to PEAR::MDB2 from PEAR::DB seeing that PEAR::DB is deprecated.

This package been superseded by MDB2 but is still maintained for bugs and security fixes.

December 26, 2006

Smarty tip for including multiple javascript files

I was looking at an article from Yahoo's Cal Henderson article called Serving JavaScript Fast.

Previously one would have a good chunk of lines to include different javascript files based on what your form was requiring for effects, etc.:

<script src="/js/menu.js" type="text/javascript"></script>
{if $js eq 'formupload'}
<script src="/js/prototype.js" type="text/javascript"></script>
<script src="/js/effects.js" type="text/javascript"></script>
<script src="/js/upload.js" type="text/javascript"></script>
{elseif $js eq 'formuploadnewsimage'}
...
{/if}

And in the template file where you include the header.tpl file you would specify which set of javascript files to also include:

{include file="header.tpl" js="formupload"}

I decided to spend a bit of time and actually get Cal's code to work from the example code (saved to plugins/insert.js.php), which I discovered that you can't invoke it from the example as:

{insert_js files="foo.js,bar.js,baz.js"}

I ended up having to do invoke it using the insert tag and specifying a name to be js so that it runs the smarty_insert_js function which is in the plugins/insert.js.php file mentioned before:

{insert name="js" files="foo.js,bar.js,baz.js"}

December 1, 2006

PHP links from around the web

Some PHP related links from around the web:

Remember: be nice to byte code caches

Mr pooteeweet, aka Lucas Smith, reminds us that the voodoo magic behind the PHP autoload functionality does not play nicely with PHP opcode caches. Be sure to read what Rasmus Lerdorf, our PHP BDFL, says about how autoloading affects opcode caching or the lack thereof of caching that stuff, the problem with adding that sort of dark voodoo magic into PHP.

Autoload is kinda convenient. Especially since in PEAR we have such a clear mapping of class name to file name. I do not really understand why some libraries and projects have these insane class name to file name mappings like ez Components and I think symfony also has them. Anyways while it seems kind of nice one must be weary of the idea that they speed up your code. If you are running a byte code cache (which anyone who cares about performance of course does) you will get quite the opposite. Here is Rasmus's answer on this taken straight from #php.pecl:

Trusted Zend Extensions

PHP's own Stefan Essar reminds us about how evil IonCube or Zend's Trusted Extensions are, which he has to pend time implementing stealth loading features in order to bypass the Zend checks. I'd prefer that the Suhosin patch for PHP, which provides additional security functionality for the PHP internals, would be applied into PHP rather than being a seperate patch. On FreeBSD the Suhosin patch is enabled by default which is good news for users at hosting companies like TextDrive (although they are only upgrading to the 5.2 branch after 5.2.1 or 5.2.2 is released).

Everyone that has used IonCube or Zend tools has most probably experienced the problem that both companies ship extensions that backdoor PHP in a way that only those extensions can be used that they consider trusted. On pages like this they claim this is another (optional) security feature. In reality it does not offer any additional security, because everyone who is able to install Zend Extensions on a server is also able to directly patch the untrusted code into the PHP installation.

The most likely real reason for these backdoors is to keep Open Source alternatives to their products away from the PHP installation.

Because of this the Suhosin extension already contains stealth loading features that are able to bypass the Zend checks. Unfortunately until today I was not aware that IonCube comes with a similiar protection that is only activated if the encoded files request it. Of course future Suhosin versions will work their way around this backdoor.

However I decided to take further actions against this kind of anti-open-source actions and will create a patch against the PHP codebase (that will also be added to Suhosin-Patch) that will introduce the concept of extension trust. The basic idea behind this feature is that the admin can give different trustlevels to extensions, so that an extension can only see those of a lower trustlevel. Additionally it will not be possible for an extension to learn it's own trust level so that the encoder backdoors cannot demand to have the highest trustlevel.

From my point of view it is really sad, that companies with a business model based on extensions and support for open source take such drastic steps against open source products.

Zeev mentions a couple of things in his response from the post about them trying to ensure compatibility and thread safety issues. Those lovely mutex locks as Clive keep reminding me, the neccessary evil to make code thread safe.

Stefan,

First, your use of the word 'backdoor' is simply wrong in my humble opinion. The word backdoor has nothing to do with what these extensions are doing - preventing potentially incompatible extensions from loading. Backdoor is a word with security connotations, so I'd appreciate it if you changed the text to reflect the fact that they 'change the behavior' or 'patch' or whatever. It's definitely not backdoor.

Secondly, the reason we (Zend) does this is to ensure compatibility. Most of the engine extensions out there are incompatible with Zend products, because they change the behavior of PHP in a way that can potentially prevent some of the hacks that we do in our products from working. I can't speak for ionCube, but as far as Zend's concerned, it's definitely not an issue of security - it's an issue of compatibility and support.

If you want to make Suhosin load in stealth mode that's entirely up to you, but it does mean that it may cause incompatible Zend extensions that make certain assumptions to crash or misbehave. I can tell you that we at Zend are now considering whether we would like to officially support systems that have Suhosin installed on them. If & when that happens, it would mean that we test our products with Suhosin installed to ensure that there are no incompatibilities or bugs in either product that trigger unwanted symptoms when they meet each other.

November 2, 2006

Interesting links from around the web

Some interesting links from around the web:

Are Lines of Code really a measure of either success, productivity or popularity?:

The title PHP Eats Rails for Breakfast and subtitle Despite the buzz around sexy new frameworks like Rails and Django, PHP is more dominant than ever initially commits the same fallacy that others have and that is to compare frameworks (Rails and Django) with programming languages. And then the suggestion becomes that one can interchangeably use Rails and Ruby, Django and Python.

Working Backwards:

In the fine grained services approach that we use at Amazon, services do not only represent a software structure but also the organizational structure. The services have a strong ownership model, which combined with the small team size is intended to make it very easy to innovate. In some sense you can see these services as small startups within the walls of a bigger company. Each of these services require a strong focus on who their customers are, regardless whether they are externally or internally. To ensure that a service meets the needs of the customer (and not more than that) we use a process called “Working Backwards” in which you start with your customer and work your way backwards until you get to the minimum set of technology requirements to satisfy what you try to achieve. The goal is to drive simplicity through a continuous, explicit customer focus.

October 29, 2006

Zend meet valgrind, valgrind meet Zend

Nothing more funny than reading a post from Stefan Esser tonight titled "Dealing with ZendOptimizer Support":

Yesterday I blogged about the fact that Suhosin-Patch is now activated by default in FreeBSD and that this will cause problems for Zend, because the ZendOptimizer accesses already freed memory which will be punished when running with a security patch that protects memory with canaries.

I also blogged about the fact that my bugreport to Zend from 3 weeks ago was simply ignored. This changed today, when a woman from Zend contacted me. (What a coincidence...)

Well under normal circumstances you are happy when a company reacts on bugreports but not when you realize that you ended up with someone from the second level support. Of course her first reaction was to blame this problem on a wrongly used ZendGuard. After that I replied to her that the problem is that Zend Optimizer is using already freed memory and that all Zend needed to reproduce this is to use a debug PHP and a ZendGuard encoded file that uses classes. And that it also might be a good idea to use valgrind on ZendOptimizer, because it will show lots of accesses to not properly allocated memory.

The response from the Zend Support lady was that according to her knowledge it is not possible to use the released ZendOptimizer with a debug PHP. She was happy to have resolved my issue with this response and if I need further technical assistance I should not hesitate to contact her.

I don't know if I should laugh or cry about this kind of support. Maybe I should just do it the Zend way: when someone tries to load a Zend product into a Suhosin-Patched PHP write a big warning message to the error log. ZendOptimizer for example does refuse to work whenever it detects a 3rd party Zend extension not in Zend's whitelist.

Maybe Zend and Andi should start hiring clued up support staff?

It's good to know that the Suhosin-Patch is enabled by default on FreeBSD. :)

October 27, 2006

CTPUG and CTMUG Meetups

The November 2006 meetups for the Cape Town PHP Users Group and the Cape Town MySQL Users Group are going to be happening on the Thursday the 2nd of November. Please RSVP to either of the meetups or both if you are going to attend.

September 20, 2006

Postgresql Project uses MySQL

Interesting to hear that the Postgresql Project, who claim to have the worlds most advanced open source database, use MySQL to power their website!

As embarressing it is to say, we've been using the MySQL version of phpAdsNew for almost a year now ... its the only one we could find that could actually keep up with the # of hits that the web sites are getting :( Even with pg_autovacuum running ...

Obviously, it wasn't something I particularly wanted to *advertise* :(

September 1, 2006

New APC Dev List

Discovered that there is now a mailing list for APC Development.

I've subscribed. Have you?

August 2, 2006

Cape Town PHP Users Group Meeting

PHP Logo
The Cape Town PHP Users Group will be having our
"first" get together on the first Thursday of September 2006 (2006-09-07).

July 31, 2006

Audio to Rasmus's PHP for Rich Internet Applications

Rasmus Lerdorf

Rasmus Lerdorf led OSCON attendees through a series of optimizations for modern web applications using PHP at O'Reilly's Open Source conference today. Most programmers use default installations and configurations for their web applications and never really dig deep within their stack or their own code to optimize page load and latency. The full slides from Rasmus's talk are available online and I recorded audio of the entire session from the front row.

Read more over at Niall's blog

May 13, 2006

Zend: Extension Writing Tutorials - Resources (Part 3)

Via phpdeveloper.org:

The Zend site has published part three of their "Extension Writing" tutorials, this time focusing on the management of resources in your extensions.

Up until now, you've worked with concepts that are familiar and map easily to userspace analogies. In this tutorial, you'll dig into the inner workings of a more alien data type - completely opaque in userspace, but with behavior that should ultimately inspire a sense of deja vu.

They start things off by describing what resources are in the Zend Engine, initializing your resources, using them, and destroying them. They mention different kinds of resources, including normal and persistent resources. There's code for each step of the way, including a sanity check at the end.

May 3, 2006

How do I invoke the Zend Framework?

There is comment on the Zend Framework Tutorial showing how Chris invokes the ZF which looks slightly different to how I'm invoking the ZF:

    <Directory "/path/to/webroot/">
      <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule . /index.php [L]
      </IfModule>
    </Directory>

May 2, 2006

PHP 5.1.3 has been released

php-version5.gifIlia has released another release of the PHP 5.1 branched - PHP 5.1.3.

The PHP development team is proud to announce the release of PHP 5.1.3. This release combines small number of feature enhancements with a significant amount of bug fixes and resolves a number of security issues. All PHP users are encouraged to upgrade to this release as soon as possible. Some of the key changes of PHP 5.1.3 include:
  • Disallow certain characters in session names.
  • Fixed a buffer overflow inside the wordwrap() function.
  • Prevent jumps to parent directory via the 2nd parameter of the tempnam() function.
  • Enforce safe_mode for the source parameter of the copy() function.
  • Fixed cross-site scripting inside the phpinfo() function.
  • Fixed offset/length parameter validation inside the substr_compare() function.
  • Fixed a heap corruption inside the session extension.
  • Fixed a bug that would allow variable to survive unset().
  • Fixed a number of crashes in the DOM, SOAP and PDO extensions.
  • Upgraded bunbled PCRE library to version 6.6
  • The use of the var keyword to declare properties no longer raises a deprecation E_STRICT.
  • FastCGI interface was completely reimplemented.
  • Multitude of improvements to the SPL, SimpleXML, GD, CURL and Reflection extensions.
  • Over 120 various bug fixes.

Further details about this release can be found in the release announcement and the full list of changes is available in the PHP 5 ChangeLog.

April 13, 2006

Block silly scrapers using PHP

This evening I sat down for a couple of minutes to write a script to block idiots people run scripts which just grab pages from ones website or abusive search engines.

View source: [ PHP Highlighted Syntax | Plain Text ]

April 12, 2006

More PHP Blogs that are not on Planet PHP

Something funky is up with the Shiftlett's regex which does some weird things to comments there so here I'm adding a list of South African PHP Blogs which are not on Planet PHP continuing from here.

Here in South Africa, we have various people who blog about PHP on their blogs:

Chris has a couple of blogs listed which I also read including:

March 21, 2006

Guess who's running ezPublish?

Zend have quietly moved over to ezPulish. Quite an interesting move, considering that once upon a time I run ezPublish on a box a few years ago cirra 2003 and had issues with slow performance. I've preferred rolling out my own CMS solutions rather than use Mambo / Joomla / ezPublish or shopping carts such as osCommerce for example.

I'm definately going to look at the latest version of ezPublish in the near future.

March 9, 2006

Die magic_quote*, safe_mode and register_globals

Good news in PHP6 register_globals, magic_quote* and safe_mode have been banished to /dev/null. About time that this occurred. I'm estatic about this!

Zend Framework 0.1.2 released

Zend Framework
The guys over at Zend have released an update to their Zend Framework:

Not even a week past our initial release and we have already updated the preview thanks to many great emails and especially our growing community on the mailing list. This release includes bug fixes, the unit test suite, and additional documentation.

The response from the our first release was overwhelmingly positive and we're upgrading our servers to cover the demand so we can open the Subversion repository shortly -- we expected the demand to be high but it exceeded even our expectations. The response from the community has been amazing with several new contributors signing on to submit code and new proposals on the table. This will be the first of many frequent updates on the road to 1.0. Please see the changelog included with the new download and enjoy the release!

Changes that have occurred to the framework:

Zend Framework                                                             NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
=RELEASE 0.1.2 / 8-Mar-2006=
- Unit test suite is now included. (Mike)
- Docs for Zend_Controller are now included. (Mike)
- Coding standards were out of date. Reported by Steph Fox. (Mike)
- Fixed default charset in Zend_Mail constructor. Reported by Jakob Buchgraber. (Mike)
- Fixed several Zend_Filter methods. (Chris)
- Fixed JSON datum encoding.  Reported by Edwin Vlieg. (Mike)
- Fixed FormRadio Helper.  Reported by AJ Tarachanowicz. (Chris)
- Fixed Zend_Uri_Http to work with new Zend_Filter. (Chris, Mike)
- Docs for the Zend_Db::factory() method were incorrect.  Reported by Dinh. (Chris)
- Zend::loadClass() now works inside __autoload().  Reported by Rob Allen. (Mike)
- Fixed notices from Zend_Pdf_Element_Dictionary.  Reported by Ralf Eggert. (Alex)
- Fixed notices from Zend_Search_Lucene_Index_SegmentWriter.  Reported by Jared Williams. (Alex)
- Removed defunct Zend_Db_DataObject docs. (Mike)
- Added NEWS.txt file (Andi)

March 5, 2006

Zend Framework for PHP5

Zend Framework
The vapourware has finally materialised yesterday. I've taken a cusory review at the Zend Framework for PHP5.

It is not all that it's cracked up to be. :( I was expecting to see more but Zend and their contributors have renamed files since the directory listing appeared on one of the contributors blogs a few months back.

   % ls                                                                          
   CVS            ZDBAdapter      ZLog             ZTemplate
   ZActiveRecord  ZException.php  ZPageController  ZUri
   ZController    ZInputFilter    ZSearch

Others are also unhappy with Zend about them being slow to release the February preview of the Zend Framework.

According to Zend:

We are glad to finally unveil the Zend Framework project. We have worked hard in the past few months with our partners and the community to get to this stage. We believe the Zend Framework can already be of great use to PHP developers, although we still have a lot of work ahead of us.

From PHP Developer

The Zend group has released today, the initial version of their framework - the Zend Framework Preview Release

We are glad to finally unveil the Zend Framework project. We have worked hard in the past few months with our partners and the community to get to this stage. We believe the Zend Framework can already be of great use to PHP developers, although we still have a lot of work ahead of us.

They have created a new site just for the framework where you can find downloads, a roadmap for the development, some FAQs about the project, and a manual to get all of the details. There will be instructions on how to access the Subversion repository soon.

Zend Framework is a high quality and open source framework for developing Web Applications and Web Services. Built in the true PHP spirit, the Zend Framework delivers ease-of-use and powerful functionality. It provides solutions for building modern, robust, and secure websites.

March 1, 2006

Poka-yoke and PHP

PHP's Marco Tabini has written an interesting article about applying the poka-yoke to PHP code in this months php|architect magazine.

Poka-yoke limits your options to the point where only one choice – the correct one – is possible.

In his example code which is provided, he shows that for example when filtering $_GET and $_POST developers should not be able to just go and set more entries into superglobals like $_GET['foo'] = 'bar'; as well as showing how to only return data via Filter::raw($key) and Filter::html($key) which returns the raw value to the requested key.

February 28, 2006

Rasmus's no-framework PHP MVC framework

Rasmus Lerdorf, Benevolent Dictator for Life, posted on his blog an entry The no-framework PHP MVC framework:

So you want to build the next fancy Web 2.0 site? You'll need some gear. Most likely in the form of a big complex MVC framework with plenty of layers that abstracts away your database, your HTML, your Javascript and in the end your application itself. If it is a really good framework it will provide a dozen things you'll never need.

I am obviously not a fan of such frameworks. I like stuff I can understand in an instant. Both because it lets me be productive right away and because 6 months from now when I come back to fix something, again I will only need an instant to figure out what is going on. So, here is my current approach to building rich web applications. The main pieces are:

MVC?

I don't have much of a problem with MVC itself. It's the framework baggage that usually comes along with it that I avoid. Even parts of frameworks can be useful as long as you can separate the parts out that you need. As for MVC, if you use it carefully, it can be useful in a web application. Just make sure you avoid the temptation of creating a single monolithic controller. A web application by its very nature is a series of small discrete requests. If you send all of your requests through a single controller on a single machine you have just defeated this very important architecture. Discreteness gives you scalability and modularity. You can break large problems up into a series of very small and modular solutions and you can deploy these across as many servers as you like. You need to tie them together to some extent most likely through some backend datastore, but keep them as separate as possible. This means you want your views and controllers very close to each other and you want to keep your controllers as small as possible.

Goals for this approach

  1. Clean and simple design
    • HTML should look like HTML
    • Keep the PHP code in the views extremely simple: function calls, simple loops and variable substitutions should be all you need
  2. Secure
    • Input validation using pecl/filter as a data firewall
    • When possible, avoid layers and other complexities to make code easier to audit
  3. Fast
    • Avoid include_once and require_once
    • Use APC and apc_store/apc_fetch for caching data that rarely changes
    • Stay with procedural style unless something is truly an object
    • Avoid locks at all costs

Be sure to read it as he explains how to rethink using the "all powerful" frameworks outthere, which makes things much more difficult to quickly get something out the door. I've been thinking about looking at using MVC but it may be best to stick away from trying for the moment and maybe attempt to try MVC with a new language like Ruby on Rails.

February 14, 2006

Joel says he does not use exceptions

Joel has been getting me to rethink my position on starting to use exceptions in PHP5.

Exceptions

People have asked why I don't like programming with exceptions. In both Java and C++, my policy is:

  1. Never throw an exception of my own
  2. Always catch any possible exception that might be thrown by a library I'm using on the same line as it is thrown and deal with it immediately.

The reasoning is that I consider exceptions to be no better than "goto's", considered harmful since the 1960s, in that they create an abrupt jump from one point of code to another. In fact they are significantly worse than goto's:

  1. They are invisible in the source code. Looking at a block of code, including functions which may or may not throw exceptions, there is no way to see which exceptions might be thrown and from where. This means that even careful code inspection doesn't reveal potential bugs.
  2. They create too many possible exit points for a function. To write correct code, you really have to think about every possible code path through your function. Every time you call a function that can raise an exception and don't catch it on the spot, you create opportunities for surprise bugs caused by functions that terminated abruptly, leaving data in an inconsistent state, or other code paths that you didn't think about.

A better alternative is to have your functions return error values when things go wrong, and to deal with these explicitly, no matter how verbose it might be. It is true that what should be a simple 3 line program often blossoms to 48 lines when you put in good error checking, but that's life, and papering it over with exceptions does not make your program more robust. I think the reason programmers in C/C++/Java style languages have been attracted to exceptions is simply because the syntax does not have a concise way to call a function that returns multiple values, so it's hard to write a function that either produces a return value or returns an error. (The only languages I have used extensively that do let you return multiple values nicely are ML and Haskell.) In C/C++/Java style languages one way you can handle errors is to use the real return value for a result status, and if you have anything you want to return, use an OUT parameter to do that. This has the unforunate side effect of making it impossible to nest function calls, so result = f(g(x)) must become:

T tmp;
if (ERROR == g(x, tmp))
     errorhandling;
if (ERROR == f(tmp, result))
     errorhandling;

This is ugly and annoying but it's better than getting magic unexpected gotos sprinkled throughout your code at unpredictable places.

Okay. So he mentions that he hates exceptions. Debugging exceptions may be more difficult. I was thinking about throwing exceptions and catching them elsewhere in the code. Going to relook exceptions over the next day, as I was thinking about stopping to rely on using PEAR's Error handling functionality.

January 22, 2006

mysql_real_escape_string() vs addslashes() vs Prepared Statements

Interesting posts by Chris and Ilia on their respective blogs.

In The addslashes() Versus mysql_real_escape_string() Debate Chris starts discussing the Google XSS exploit and then goes on to explaining about character set encoding and how one particular character set allows for this exploit:

Last month, I discussed Google's XSS Vulnerability and provided an example that demonstrates it. I was hoping to highlight why character encoding consistency is important, but apparently the addslashes() versus mysql_real_escape_string() debate continues. Demonstrating Google's XSS vulnerability was pretty easy. Demonstrating an SQL injection attack that is immune to addslashes() is a bit more involved, but still pretty straightforward.

In GBK, 0xbf27 is not a valid multi-byte character, but 0xbf5c is. Interpreted as single-byte characters, 0xbf27 is 0xbf (¿) followed by 0x27 ('), and 0xbf5c is 0xbf (¿) followed by 0x5c (\).

How does this help? If I want to attempt an SQL injection attack against a MySQL database, having single quotes escaped with a backslash is a bummer. If you're using addslashes(), however, I'm in luck. All I need to do is inject something like 0xbf27, and addslashes() modifies this to become 0xbf5c27, a valid multi-byte character followed by a single quote. In other words, I can successfully inject a single quote despite your escaping. That's because 0xbf5c is considered to be a single character, not two. Oops, there goes the backslash.

Ilia then goes onto writing in his piece mysql_real_escape_string() versus Prepared Statements he goes more into detail about the exploit.

Chris has written a compelling piece about how the use of addslashes() for string escaping in MySQL queries can lead to SQL injection through the abuse of multibyte character sets. In his example he relies on addslashes() to convert an invalid multibyte sequence into a valid one, which also has an embedded ' that is not escaped. And in an ironic twist, the function intended to protect against SQL injection is used to actually trigger it.

The problem demonstrated, actually goes a bit further, which even makes the prescribed escaping mechanism, mysql_real_escape_string() prone to the same kind of issues affecting addslashes(). The main advantage of the mysql_real_escape_string() over addslashes() lies in the fact that it takes character set into account and thus is able to determine how to properly escape the data. For example, if GBK character set is being used, it will not convert an invalid multibyte sequence 0xbf27 (¿’) into 0xbf5c27 (¿\’ or in GBK a single valid multibyte character followed by a single quote). To determine the proper escaping methodology mysql_real_escape_string() needs to know the character set used, which is normally retrieved from the database connection cursor. Herein lies the “trick”.

January 13, 2006

PHP 4.4.2 has been released

The PHP development team is proud to announce the release of PHP 4.4.2. This release address a few small security issues, and also corrects some regressions that occurred in PHP 4.4.1. All PHP 4 users are encouraged to upgrade to this release. Some of the key changes of PHP 4.4.2 include:

  • HTTP Response Splitting has been addressed in the header() function.
  • An XSS problem inside the error reporting functionality has been removed.
  • Apache 2 regression with sub-request handling on non-Linux systems has been fixed.
  • A regression with the key() and current() functions have been fixed.
  • Over 30 various bug fixes.

Further details about this release can be found in the release announcement
and the full list of changes is available in the PHP 4 ChangeLog.

January 12, 2006

PHP 5.1.2 has been released

php-version5.gif

Ilia has released another release of the PHP 5.1 branched - PHP 5.1.2.

The PHP development team is proud to announce the release of PHP 5.1.2. This release combines small feature enhancements with a fair number of bug fixes and addresses three security issues. All PHP 5 users are encouraged to upgrade to this release. Some of the key changes of PHP 5.1.2 include:
  • HTTP Response Splitting has been addressed in ext/session and in the header() function.
  • Fixed format string vulnerability in ext/mysqli.
  • Fixed possible cross-site scripting problems in certain error conditions.
  • Hash & XMLWriter extensions added and enabled by default.
  • Upgraded OCI8 extension.
  • Over 85 various bug fixes.

Further details about this release can be found in the release announcement and the full list of changes is available in the PHP 5 ChangeLog.

January 11, 2006

PHP Notice: Undefined variable: _SERVER

One loves discovering PHP annoyances. Turns out numerous lines like the ones below is caused by a feature called Just In Time (JIT) creation of the $_SERVER and $_ENV super globals.

PHP Notice:  Undefined variable: _SERVER in *snip* on line XX
PHP Notice:  Undefined variable: _SERVER in *snip* on line XX
...

And the simplest way to fix this? either use in the script global $_SERVER; or set in your php.ini file:

auto_globals_jit = Off
When enabled, the SERVER and ENV variables are created when they're first used (Just In Time) instead of when the script starts. If these variables are not used within a script, having this directive on will result in a performance gain. The PHP directives register_globals, register_long_arrays, and register_argc_argv must be disabled for this directive to have any affect.

December 29, 2005

Komodo anyone?

Komodo LogoThere is a promo code which gives you the personal edition of Komodo for free ;) As a late Christmas present from ActiveState.

Well worth the effort for a IDE and is built upon Mozilla's XUL framework.

Award-winning IDE for dynamic languages, providing a powerful workspace for editing, debugging and testing your programs. Komodo offers advanced support for Perl, PHP, Python, Ruby, and Tcl. Komodo runs on Linux, Mac OS X, Solaris, and Windows.

UPDATE:

The offer ends on December 31st 2005.

December 28, 2005

Simplifying PHP Form Processors (Part II)

I've been thinking quite a bit more on the subject of Simplifying PHP Form Processors. I think it would be important for the community to come up with a solution to the problem. The form processor, which I'm busy working on at the moment currently looks like (utilising bits and pieces of code I've developed over the past couple of years):


<?php
/**
 * @author      Jacques Marneweck <jacques@php.net>
 * @copyright   2002-2005 Jacques Marneweck.  All rights reserved.
 * @version     $Id$
 */

Class FormValidator {
    var 
$errors = array ();
    var 
$fields = array ();

    
/**
     * Generate a signature for form data to verify that the data has not
     * changed
     *
     * @param   mixed   data
     * @return  string  sha1 hash of serialized data
     * @access  public
     */
    
function signature ($data) {
        
$ctx sha1(serialize($data));
        return (
$ctx);
    }

    
/**
     * Check a required field is filled out
     *
     * @param   array   required fields
     * @param   array   post data
     * @return  array   errors
     * @access  public
     */
    
function checkrequired ($required$data) {
        foreach (
$required as $field => $reason) {
            if (!isset(
$data[$field]) || empty($data[$field])) {
                
$this->errors[] = $reason;
                
$this->fields[] = $field;
            }
        }
    }

    
/**
     * Retrieve an array of error messages
     *
     * @return  array   array of error messages
     * @access  public
     */
    
function geterrors () {
        return (
$this->errors);
    }

    
/**
     * Retrieve an array of fields that have missing / invalid data
     *
     * @return  array   array of fields
     * @access  public
     */
    
function getfields () {
        return (
$this->fields);
    }

    
/**
     * Check if the form has errors
     *
     * @return  bool    true if has errors else false
     * @access  public
     */
    
function haserrors () {
        if (
sizeof($this->errors) > 0) {
            return 
true;
        } else {
            return 
false;
        }
    }

    
/**
     * Check if a form has successfully validated and does not have
     * errors
     *
     * @return  bool    true if valid else false
     * @access  public
     */
    
function isValid () {
        if (
sizeof($this->errors) === 0) {
            return 
true;
        } else {
            return 
false;
        }
    }
};

There are various things which need to be taken into consideration, which I've been thinking about quite a bit lately which affect various people involved in the normal development process:

  • Making it easier from a presentation point-of-view to allow designers to allow say changing the row background to red for a row where there is an error, to displaying say a red exclaimation mark, displaying a error message below / above the field
  • a better way for rule processing first checking if the field is compulsory, and then going through the rest of the ruleset checking if there is more errors rather than saying that you need to enter a new password and password confirmation does not match, etc.
  • allowing developers to control the rulesets that are required per the specifications document rather than leaving it in the web designers hands to change without anyone noticing / reading the web designers commit messages.

December 27, 2005

Simplifying PHP Form Processors

Making a simple easy to use web form processor for PHP keeps coming up on projects. The usual way which I've seen people implement form processing are:

  • just relying on JS validation on the webbrowser for form processing, which does not prevent people from disabling JS in their webbrowser and you're back at square one without having any form validation as it's bypassed
  • minimal error checking for if a value is set
  • long winded approach checking each required field is set, etc. as well as verifying that the inputted variables have been scrubbed and are clean, and then get checked against true / false, for dropdowns if a value appears on the dropdown, etc.

Simon Willison has published his implementation of a form processor which looks quite promising for processing forms. This example shows how to call the form and includes all the error code and validation requirements as part of the XHTML document, which it strips prior to sending to the webbrowser.

I was initailly thinking that it would be useful to have a XML document that goes hand in hand with a form (rather than including the form processors ruleset within the form). That way you can have multiple forms on a page and use the various xml files to get the ruleset data for processing.

The form processor would need to do all the variable scrubbing for you. Chris Shiflett's Essential PHP Security: Forms and URLs explains this in more details:

This chapter discusses form processing and the most common types of attacks that you need to be aware of when dealing with data from forms and URLs. You will learn about attacks such as cross-site scripting (XSS) and cross-site request forgeries (CSRF), as well as how to spoof forms and raw HTTP requests manually. By the end of the chapter, you will not only see examples of these attacks, but also what practices you can employ to help prevent them.

<?php 

$html 
= array();

$html['username'] = htmlentities($clean['username'],
                    
ENT_QUOTES'UTF-8');

echo 
"<p>Welcome back, {$html['username']}.</p>";

?>

In the example above Chris demonstrates escaping output back to the webbrowser. I tend to use the Smarty Template Engine to seperate HTML away from the PHP code which I'm developing. In Smarty 2.6.11, you can specify which character set you need to use with the escape function e.g. {$foobar|escape:"htmlall":"UTF-8"}

December 20, 2005

PHP Security Audit Comic

Richard Davey has posted a comic strip called "PHP Life : Dreaded Words".

Disclaimer: This strip does not imply that having your code checked by Stefan would be a nerve wracking experience! Infact I'm certain he'd do an amazing job. But boy, wouldn't waiting for the results worry you just a little?! :-)

December 2, 2005

PHP 5 and namespaces

The developers of the PHP Namespaces in violation of the PHP license :( But lets not go into the license violation. There was a massive thread on the PHP internals mailing list about namespaces and who liked what ascii character to specify namespaces. Rasmus even went as far as to say that : and :: are not going to be valid.

Ideally you can import say PEAR's Date class into the PEAR namespace while using Derick's Date class in the the PHP namespace. Not sure which implementation they are going to implement but apparenlty there are four including one from Dimitry from Zend Technologies who originally wrote the Turck MMCache software.

November 28, 2005

PHP 5.1.1 Released

php-version5.gif
Ilia has released another release of the PHP 5.1 branched - PHP 5.1.1. Nearly four days after the initial release of PHP 5.1.0 and the sneaky code commit which has been disabled :)

The PHP Development Team would like to announce the immediate release of PHP 5.1.1. This is a regression correction release aimed at addressing several issues introduced by PHP 5.1.0, the core changes as follows:
  • Native date class is withdrawn to prevent namespace conflict with PEAR's date package.
  • Fixed fatal parse error when the last line of the script is a PHP comment.
  • eval() hangs when the code being evaluated ends with a comment.
  • Usage of \{$var} in PHP 5.1.0 resulted in the output of {$var} instead of the $var variable's value enclosed in {}.
  • Fixed inconsistency in the format of PHP_AUTH_DIGEST between Apache 1 and 2 sapis.
  • Improved safe_mode/open_basedir checks inside the cURL extension.

The complete details about all of the changes can be found in the PHP 5 ChangeLog.

November 27, 2005

PHP 5.1.0: How To throw allegations around

I tend to occassionally respond to emails send to the PHP internals mailing list about the future of PHP. Over the past few days there has been allegations of Derick being dishonest by sneaking new functionality into PHP 5.1.0 before the last release candidate by lieing to Ilia (who took over being release manager).

Then there are flame wars going backwards and forwards about who's fault it is, etc. etc. Now there is a way too many emails about whether to use namespaces.

John found an interesting quote about the software development process:

Later that day... I stumbled on this quote by Dave Winer:

It seems the computer industry hasn't gotten to the stage yet where it can really deliver delight to users. Maybe we spend too much time trying to fuck up the user experience. I think of that when I see pages with fifteen different formats that all do the same thing. Why? There's no need for it. How many of those types of battles were fought inside Apple that resulted in the super-shitty experience I had and Jeremy had. Maybe we need to take a step back and start thinking a bit about how this kind of bullshit keeps us from growing.

I haven't been reading the PHP internals mailing lists since August this year, but because of the rumored PHP 5.1 mishaps, I did. The in-fighting and name-calling is surprisingly heated. Open source is certainly great, the price-point is good, you can fix things yourself (if you have the skill), but the meandering directions that PHP takes can be frustrating. Some people want a more advanced programming language to keep up with the Rubies and Pythons; others (like me), want 100% backward compatibility. The Bazaar (and perhaps all software development for that matter) is sometimes too bizarre.

But in the meantime expect a PHP 5.1.1 release in the next day or two disabling Derick's new date class. The moral of the story is these days wait until a maintenance release comes out before upgrading your PHP install?

November 25, 2005

Strict session handling in PHP

Christopher Kunz mentions a new patch for PHP which deals with Session Fixation.

PHP has a permissive session system. This has been decided way before I came into the PHP world (I guess in preparation of 4.0), and the reasons for this decision are kinda lost in transit. However, with a small patch by Hardened-PHP Project buddy Stefan esser, this might now change.

A small patch against PHP's ext/session and ext/sqlite adds two new handler functions to validate and create session IDs, as well as the php.ini setting

session.use_strict_mode = 0/1

although under normal circumstances, a strict session mode handler will not bring extremely more security, it will put an end to session fixation (supplying a session ID and have it validated by PHP), some SQL injection issues (if, for tracking purposes, you store each session ID in a database) and some XSS that might arise from providing a session ID including HTML/JS code.

You can check out the patch at: http://www.suspekt.org/session_strict_mode.patch

It will also be part of the next release of the Hardening Patch for PHP.

Hopefully we can see some of the Hardened PHP Patch ideas merged into the main PHP source code in the near future.

November 24, 2005

PHP 5.1.0 has been released

php-version5.gif
PHP 5.1.0 has been unleashed on the masses.

[24-Nov-2005] The PHP development team is proud to announce the release of PHP 5.1.0.
Some of the key features of PHP 5.1.0 include:

  • A complete rewrite of date handling code, with improved timezone support.
  • Significant performance improvements compared to PHP 5.0.X.
  • PDO extension is now enabled by default.
  • Over 30 new functions in various extensions and built-in functionality.
  • Bundled libraries, PCRE and SQLite upgraded to latest versions.
  • Over 400 various bug fixes.
  • PEAR upgraded to version 1.4.5

In addition to new features, this release includes a number of important security fixes and we recommend that all users of PHP 5.0 and early adopters of PHP 5.1 betas upgrade to this release as soon as possible.
The complete details about all of the changes can be found in the PHP 5 ChangeLog and an upgrading guide is available as well.


PHP 5.1.0 is the upgrade path for the PHP 5.0.X series, which has been in production since PHP 5.0.0 was released in July last year.

October 24, 2005

PHP Encoders offer little protection

PHP Encoders Protection where are you? is a blog entry on the PHP Security Blog where Stefan Esser writes:

From time to time people ask if it is possible to use the Hardening-Patch together with the IonCube Encoder or the ZendEncoder. I usually answer, that they should ask the IonCube support or the Zend support, to simply create compatible versions.

This will change in the future. I had a look at both encoders that are most probably the most famous ones and I am kinda shocked. The IonCube Encoder does not offer any protection against oparray_dumping or oparray disassembly. If you want to see this for yourself, then download derick and andrei's vld and apply the following patch: vle-request-hack.diff. After you have applied this, simply load the IonCube Loader as normal and activate vld as usual.

You will see the disassembly of the encoded PHP script in ZendEngine Opcodes and you will most probably not notice any obfuscation at all... (You can always compare the output to the output of the not encoded version)

The good news for all the users of ZendEncoder (or however it is called nowadays) is, that it is a little bit harder to get the disassembly of scripts that were encoded with ZendEncoder, because you will notice that the Opcodes are encrypted. But anyone skilled with runtime encryption layers will be able to decrypt those opcodes. When you have broken the opcode encryption they look like the output of ZendOptimizer. Which means there are some ZentOptimizer specific opcodes in it, that have something todo with cached functionnames...

I think this is quite bad news for Zend and the various other providers of PHP Encoders as they'll have their work set out for themselves to produce a more secure encoding mechanism whereby people cannot easily get to the unencrypted opcodes.

I've found the following comment on a chineese forum:

Hello,

We are aware of this problem, even before it reached China.

There is work being done now to develop the next generation of Zend Encoder that will have stronger encoding and will be harder to crack and decode.

You have to keep in mind that there is no encoding (or even encryption) mechanism that is 100% safe, especially something that needs to be decoded and parsed fast like a php script. Also, even though it is not uncrackable, Zend Encoder is the best solution in the market right now for encoding php code - and it provides a decent protection for most people.

September 28, 2005

Using HORDE in your site

Jan Schneider has written an article about How to embed Horde applications into your website

I have written a small howto in the Horde Wiki that explains how to embed Horde applications into your own website or web application.

"Using Horde from a custom website or application" explains how to call API methods in Horde or one of the Horde applications from a PHP script that is not part of Horde itself. The howto contains several code examples and also shows how to embed complete HTML snippets into larger web site pages.

September 7, 2005

Ilia's php|architect's Guide to PHP Security

php|architect's Guide to PHP Security
Ilia has written a php|architect's Guide to PHP Security and has announced that it has been sent for publishing.

For those who don't know, Ilia is one of the leading PHP security experts in the PHP community.

Despite all the negative publicity, however, PHP is and remains a very stable--and very secure--programming environment. php|architect's Guide to PHP Security, written by security expert (and frequent php|architect contributor) Ilia Alshanetsky, provides you with a guide that covers everything you need to secure existing PHP applications and write new ones with security in mind.

September 1, 2005

Do you flickr?

Flickr logo

Rasmus Lerdorf has posted Flickr API Fun.

I like stuff I can pick up and do something useful with in an hour or two. Perhaps my attention span is too short, but if I have to read a 300 page spec before I get to Hello World, then it's not for me. Or you would at least have to pay me a lot of money to suffer through it. I think people refer to this as "immediacy". For me I think it is mostly lazyness. If I can't figure it out in an hour, it's broken as far as I am concerned.

I feel similar to Rasmus about things which one can pick up in an our or two.

August 30, 2005

Database query caching

I'm busy spending time adding more features to my PHP Application Framework called the Tshukudu Application Framework which currently is quite a liteweight PEARish framework for PHP4 and PHP5. It's moving towards dropping PHP4 in the near future.

I've spent some time fiddling with the idea of caching database query results to disk instead of to a memcached servers when in a shared hosting environment to reduce load on a database server when looking up data which does not change very often. By caching database queries, it reduces the amount of work the database has to do to look up data considering the larger the dataset, the more data has to flow between MySQL and PHP.

Quite surprisingly I stumbled across an article titled Caching PHP Programes with PEAR on O'Reilly written by Sebastian Bergmann. Interesting read none the less.

So I created a class called DB_Cache which currently just extends PEAR Cache as well as keeping a DB connection open for sending queries to. The Cache_Memcached connects to Memcached servers to retrieve and store data while DB_Cache (should more likely be called Cache_DB_File in reality) caches database result sets to a file on the filesystem via Cache (which it extends).

A couple ideas behind the framework is to provide functionality for speeding up PHP sites by having different levels of caching within a PHP application such as caching content from remote servers, caching database resultsets, etc.

Utilisation of the code looks something like:

<?php
require_once 'Tshukudu/DB/Cache.php';
$db_cache = new DB_Cache;
$users = $db_cache->query("SELECT * FROM users LIMIT 0,10", 'getall'));

Ugly but needs a slight rewrite to rather extend DB_MySQL in mycase instead of Cache.

August 17, 2005

+5 Insightful

There has been quite a bit of discussion regarding the start of development on PHP 6.0. Various people have been complaining that we should not be discussing the future of PHP on our blogs, et. al.

Rasmus Lerdorf posted the following comment to Marco's blog, which sums it up nicely.

It is interesting how much attention our PHP 6 discussions have been getting and even some criticisms that we shouldn’t be talking about it, or at least we shouldn’t be talking about it publically since PHP 5 is still pretty new to people. Work on PHP 5 started in November 2002. No significant structural changes are going to go into PHP 5 at this point. Minor enhancements and plenty of bug fixes to solidify it will continue for a long time, but given this it is natural that we start looking ahead to PHP 6. People should be worried if we weren’t looking ahead at this point. And given that we are an open source project, these discussions must happen in the open even if it gives people ammunition to use against us. Wouldn’t you love to see the internal developer discussions about what sucks in a number of proprietary products out there? Would it make you stop using the product if you saw its developers discussing weaknesses and proposing solutions or enhancements?

Occasionally we form smaller closed groups of developers to tackle a tricky problem and crank out some code quickly. The Unicode effort was an example of that, but the result of the work was made public as soon as it was feasible and didn’t interfere with more pressing work on PHP 5. And it is far from done. We are a long way from PHP 6 still and we need the ideas to keep flowing and people need to keep discussing them.

August 16, 2005

PHP 5.1.0RC1

Zeev has rolled PHP 5.0.1 release candidate 1 a little earlier today:

August 15, 2005

The state of PHP

PHP is moving on towards gearing itself for PHP 6.0.

Andrei started warning people to not commit to HEAD as he was about to start committing his Unicode support for PHP. He mentions in his blog post:

The project that we have been working on for the past 4 months is finally seeing the light of day: yesterday I merged the Unicode support into the public PHP tree. I was going to say that my part of the hard work is done, but I guess I still have to edu-ma-cate developers about Unicode and other finer things in life. :)

Our Benevolent Dictator for Life, Rasmus Lerdorf, decided to email the internals list discussing a "PHP 6.0 Wishlist" which started a thread of over 150 email messages since Friday evening!

Various things on Rasmus' initial list which interests me from a enterprise adoption view includes getting rid of

  • register_globals
  • magic_quotes
  • safe_mode

The adding of an opcode cache should have been added a long time ago, more to Zend's dislike for that to be included on the list, as when Andi and Zeev implemented the Zend Engine, they left out the opcode cache and built their business around an opcode cache (Zend Accelerator).

Other PHP'ers comments on the 'state of PHP':

July 29, 2005

Apache and OpenSSL Issues

Occassionally apache with mod_ssl just breaks after doing an operating system upgrade or even just upgrading openssl. Doing a backtrace against the httpd.core file (gdb httpd httpd.core) I got a backtrace which revealed to me the following:

(gdb) bt
#0 0x00000018 in ?? ()
#1 0x28445162 in RSA_new_method () from /lib/libcrypto.so.3
#2 0x28444eea in RSA_new () from /lib/libcrypto.so.3
#3 0x2845e7e8 in RSAPrivateKey_asn1_meth () from /lib/libcrypto.so.3
#4 0x2846a8a6 in ASN1_item_ex_new () from /lib/libcrypto.so.3
#5 0x2846a6c3 in ASN1_item_ex_new () from /lib/libcrypto.so.3
#6 0x2846621c in ASN1_item_ex_d2i () from /lib/libcrypto.so.3
#7 0x28465c85 in ASN1_item_d2i () from /lib/libcrypto.so.3
#8 0x2845e89f in d2i_RSAPublicKey () from /lib/libcrypto.so.3
#9 0x28459b2c in d2i_PublicKey () from /lib/libcrypto.so.3
#10 0x284585b5 in X509_PUBKEY_get () from /lib/libcrypto.so.3
#11 0x28457615 in X509_get_pubkey () from /lib/libcrypto.so.3
#12 0x28375749 in ssl_util_algotypeof () from /usr/local/libexec/apache/libssl.so
#13 0x2836d226 in ssl_pphrase_Handle () from /usr/local/libexec/apache/libssl.so
#14 0x28366f3f in ssl_init_Module () from /usr/local/libexec/apache/libssl.so
#15 0x08057092 in ap_init_modules ()
#16 0x0805fd83 in main ()

Basically what the backtrace gives us back informs us that there is a problem with OpenSSL. Normally the way to resolve this is to recompile apache+mod_ssl as well as php's openssl extension using portupgrade and force it to do the upgrade, and magically next time you run "apachectl startssl" it works.

July 28, 2005

Rasmus' 30 second AJAX Tutorial

PHP's Benevolent Dictator for Life, Rasmus Lerdorf, wrote a 30 second AJAX Tutorial in response to various people discussing on the php-general mailing list how AJAX is going to change web development.

I find a lot of this AJAX stuff a bit of a hype. Lots of people have been using similar things long before it became "AJAX". And it really isn't as complicated as a lot of people make it out to be. Here is a simple example from one of my apps. First the Javascript:

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sndReq(action) {
http.open('get', 'rpc.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}

function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();

if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}


This creates a request object along with a send request and handle response function. So to actually use it, you could include this js in your page. Then to make one of these backend requests you would tie it to something. Like an onclick event or a straight href like this:

<a href="javascript:sndReq('foo')">[foo]</a>

That means that when someone clicks on that link what actually happens is that a backend request to rpc.php?action=foo will be sent.

In rpc.php you might have something like this:

  switch($_REQUEST['action']) {
    case 'foo':
      /* do something */
      echo "foo|foo done";
      break;
    ...
  }

Now, look at handleResponse. It parses the "foo|foo done" string and splits it on the '|' and uses whatever is before the '|' as the dom element id in your page and the part after as the new innerHTML of that element. That means if you have a div tag like this in your page:

<div id="foo">
</div>

Once you click on that link, that will dynamically be changed to:

<div id="foo">
foo done
</div>

That's all there is to it. Everything else is just building on top of this. Replacing my simple response "id|text" syntax with a richer XML format and makine the request much more complicated as well. Before you blindly install large "AJAX" libraries, have a go at rolling your own functionality so you know exactly how it works and you only make it as complicated as you need. Often you don't need much more than what I have shown here.

Expanding this approach a bit to send multiple parameters in the request, for example, would be really simple. Something like:

  function sndReqArg(action,arg) {
    http.open('get', 'rpc.php?action='+action+'&arg='+arg);
    http.onreadystatechange = handleResponse;
    http.send(null);
  }

And your handleResponse can easily be expanded to do much more interesting things than just replacing the contents of a div.

-Rasmus

Secure PHP Coding

Over at I love Jack Daniels there is another article about Writing Secure PHP, Part 3.

n Writing Secure PHP and Writing Secure PHP, Part 2 I covered many of the basic mistakes PHP developers make, and how to avoid common security problems. It is time to get a little deeper into security though, and begin to tackle some more advanced issues.

July 11, 2005

Differences of opinion

Tobias Schlitt has an blog entry titled A clash of asociality on his blog which made a bit of amusing reading considering certain commit messages to the PEAR website code.

Open sources are great things, annoying things too. For example, take the PEAR project. There is a huge croud of developers in the project (more than 800 registered users on PEARWeb, more than 200 maintainers), which every day try to improve the project, try to work together and try to learn from what they code and from the code they read. They feel the spirit of open source, they invest much time and train their hard skills in coding and their soft skills in the cooperation with a team.

But every now and then it happens that there is a black sheep under those fine 800, someone who even doesn't seem to know, what "soft skills" means. Surely, it happens not often, but some there are. Those re-appear now and then, vituperate as much as they can, hastily commiting some code ("fixing up other peoples crap"), which does not even work or better to say, hasn't even seen a syntax check. Finally those people bring project internal problems to the public perverting the facts as much as possible for their own advantage. But thankfully, those people tend to disappear again as fast as they have appeared before...

Maybe certain people who don't run syntax checkers against their code before committing should loose cvs commit to pearweb for a few days while they learn how to use command line syntax checker? ;)

PHP 4.4.0 has been released

php-version4.gifPHP 4.4.0 has been released!

The PHP Development Team would like to announce the immediate release of PHP 4.4.0. This is a maintenance release that addresses a serious memory corruption problem within PHP concerning references. If references were used in a wrong way, PHP would often create memory corruptions which would not always surface and be visible. The increased middle digit was required because the fix that corrected the problem with references changed PHP's internal API. PHP 4.4.0 does not have any new features, and is solely a bugfix release.

Release Announcement.

July 2, 2005

Progress on PEAR Cache_Memcached

Still working on the my PEAR Cache_Memcached project. The proposal is still in first draft stages as I still have certain things to do prior to changing the proposal from 'draft' to 'proposed'.

July 1, 2005

PEAR Cache_Memcached Proposal

Regarding my PEAR Cache_Memcached proposal it is still in 'draft' stages. I still have a small amount of work to finish prior to 'proposing' the proposal. Please feel free to comment on this on this blog post.

June 29, 2005

Changes to PHP 4.4.0 which breaks backwards compatibility

php-version4.gifThere is a change with references which breaks backwards compatibility in version of PHP >= 4.4.0.

Many people seem, including myself, at times have incorrectly used references in code similar to John's code below:

<?php
function &dosomething($a)
{
    
$b = false;
    return empty(
$a) ? $b : $a;
}

According to resident PHP guru Derick Rethans, "this is actually correct behavior. The ?: operator creates a copy and the you returning by reference doesn't work of course." On his blog he also wrote:

Through Planet PHP I saw the blog entry "Is PHP staying the language I want to work with?", for with comments are cowardly disabled. Although the way classes are handled is debatable, moaning that PHP 4.4 breaks "return ($ret)" when returning by reference only shows that the programmer has had no clue about references in the first place. If you place () around a variable, you're making it an expression. You can only return variables by references, not expressions. The return-by-reference in this function never could have worked as it should have in the first place. Clue: Don't use "return ()", but just "return ".

Derick also has a article in the June 2005 issue of php|architect where he explains what references are in more detail.

The PHP Manual is a bit misleading about returning references on the return() function page but on the returning values page it shows one should be returning references without using the ()'s as part of the call to return.

June 24, 2005

PHP 5.1.0 beta 2 is out

PHP 5.1 Beta 2 is now available! A lot of work has been put into this upcoming release and we believe it is ready for public testing.

Some of the key improvements of PHP 5.1 include:

  • PDO (PHP Data Objects) - A new native database abstraction layer providing performance, ease-of-use, and flexibility.
  • Significantly improved language performance mainly due to the new Zend Engine II execution architecture.
  • The PCRE extension has been updated to PCRE 5.0.
  • Many more improvements including lots of new functionality & many bug fixes, especially in regards to SOAP, streams and SPL.
  • See the bundled NEWS file for a more complete list of changes.

Everyone is encouraged to start playing with this beta, although it is not yet recommended for mission-critical production use.

June 18, 2005

Object Overloading in PHP 5

A fine implementation of the object-overloading paradigm has found its way into PHP version 5. This article explores the possibilities of the overload methods __call(), __set(), and __get(). After explaining the basic theory of overloading, it dives straight into the topic by using two practical examples: first, implementing persistable classes, and second, figuring out a way to realize dynamic getter and setter methods. If you do not yet know what these terms mean, don't be afraid--it will become clear to you when you see the example code.

Check out Martin's article.

June 17, 2005

Legal issues with bug reports?

When reporting bugs to the PHP one user claims to be having "Legal Issues", hence he cannot submit repoduce code. Derick reports:

Some times people don't want to submit their code when filing a bug report for PHP because of "Legal Reasons". They simply assume we can fix it even with their very vague reasons. Usually we persist in asking for more information because we're nice and want to help those people who think they found a bug anyway. Sometimes this gives hiliarius responses. Come on, your über-cool "new technology" with PHP - we're that ones that gave you the tool to write your "new technology" in the first place. Even better is when they claim that "they're not allowed to tell you what it is".

But it gets, better - now the guy is even offering that we debug his large application for us, but we need to sign an NDA as well then. I'm not sure in which world this guy lives, but an NDA for a bug report? :) If you can't make a short reproducable case, then you're pretty much lost anyway. I just ended up asking how much they pay.

June 8, 2005

A decade of PHP

Today marks the 10th anniversary of PHP. Rasmus initially announced PHP 1.0 10 years ago today.

It is amazing how PHP has changed the web coding landscape. I remember back in the day using various combinations of shell scripts to generate HTML pages for various sites I was fiddling on for the 'semi dynamic content'. I rewrote some Novell netbasic scripts in perl for the #Cape_Town website where users had the ability to use the nickbrowser to view details about other people on that channel. The site was rewritten from scratch with a CMS, where the webteam members could post data, users could submit their own profile, and do various other bits and pieces. It was initially written using PHP3 and used Matt Robinson's file based session library which was the de-facto session management library for PHP3. The #Cape_Town website was one of my first websites developed with PHP, as it was much quicker and easier to do web development with PHP compared to perl.

Rasmus really did a great thing by inventing, sharing and nurturing PHP. While many, many people made it all happen, Rasmus (and, indirectly, Rasmus' wife Christine) is the baling wire and duct tape that held it all together.

There are numerous blog entries regarding PHP's 10th anniversary including that entry on the PHP.net homepage.

Zak sums it up better than I could:

Rasmus really did a great thing by inventing, sharing and nurturing PHP. While many, many people made it all happen, Rasmus (and, indirectly, Rasmus' wife Christine) is the baling wire and duct tape that held it all together.

June 6, 2005

Writing PHP Extensions part II

Sara Golemon, PHP Developer, has written part II to an article on programming extensions for PHP. This article deals with Parameters, Arrays and ZVAL's. Her first article was Part I: Introduction to PHP and Zend.

Core developer and 'PECL Princess' Sara Golemon has written a number of extensions for PHP 4 and 5. She is also the person most likely to respond sympathetically to newcomers' queries about PHP internals.

This combination of hands-on experience and patience made Sara the natural choice to write an introductory series to PHP extension programming for zend.com.

June 5, 2005

PHP Compiler Halt Patch

Ilia posted a patch some time ago to the PHP Internals mailing list about making it possible to stop parsing a php file when you want to extract content from the bottom of the script such as a tarball.

Ilia has more including some 'sample code'.

June 1, 2005

Using php5-fcgi

I suppose one of the things that was hacking me off about php5-fcgi was that it was ignoring the .htaccess file (rightfully so) and required a bit of tweaking of a custom php.ini for the php fastcgi to utilise so that one would get certain settings going prior to utilising my normal auto-prepend file.

For the past few weeks I've had to have quite a bit of stuff towards the top of my php scripts:

<?php
if ($_SERVER['SERVER_ADDR'] == 'XXX.XXX.XXX.XXX') {
    
ini_set ('include_path', '*snip*');
    
ini_set ('magic_quotes_gpc', 'off');
    
ini_set ('magic_quotes_runtime', 'off');
    
ini_set ('register_globals', 'off');
    
ini_set ('display_errors', 'on');
    
ini_set ('display_startup_errors', 'on');
    require_once
'powertrip-prepend.php';
}

Using the custom php.ini for the php5-fcgi one can manually edit the custom php.ini and set various settings which you would have normally have set in your .htaccess or httpd.conf depending on your environment.

Anyway I changed the line from:

PHPRC="/usr/local/etc"

to

PHPRC="/home/jacques/etc/php5"

which sorted out a couple of "issues" I was having. I have in the past always prefered using the apache configuration file for storing various settings for the virtual host including php specific settings.

May 31, 2005

doc.php.net API docs online

I'm now generating API documentation for the doc.php.net (docweb) website which is available online which is generated using phpDocumentator.

Ideally this means that those who are working on docweb will now document their code ;)

May 27, 2005

news.php.net is back

Good news! news.php.net is back up and running with an upgraded version of Jim Winstead's Colobus.

May 25, 2005

SMS_Clickatell 0.6.1 Released

I've rolled a 'maintenance release' of SMS_Clickatell this evening which utilises the SMS_Clickatell::_curl function for using one curl handler to the Clickatell API server which reduces having to open a new connection for each request to the Clickatell API Server.

Continue reading "SMS_Clickatell 0.6.1 Released" »

May 24, 2005

SMS_Clickatell API Docs online

I've uploaded the SMS_Clickatell API docs online tonight, which I have generated using phpDocumentator. At some stage I'm going to hack a custom phpDocumentator theme for this site.

Continue reading "SMS_Clickatell API Docs online" »

Validate_ZA is a seperate package now

The Validate package was split up so that Validate_ZA is now a seperate package.

I'm planning on making some modifications to the package over the next week or two. Documentation will also be available in a bit.

May 6, 2005

PHP 2000 Meeting Pictures

PHP 2000 Meeting Pics are online after Zeev found them in his homedir.

May 3, 2005

Andi is another reality when it comes to help

Andi Gutmans, asked the question if there is a good web-based help system for PHP?

I have been searching a lot for a decent help system for PHP applications. The idea is something similar to the Microsoft HTML Help (CHM) or Web help generated by Macromedia Robohelp. I'd be interested to hear more from people about what their thoughts are regarding this topic.

In general, such a system should be a set of XSLT stylesheets to compile DocBook help into HTML and PHP, so it is easily deployable over the web. It should be able to compile any existing DocBook documentation without modifying it (for example the PHP manual).

Livedocs was mentioned and someone also mentioned about Zend funding someone to do the relevant work on livedocs.

Zend could make up a bounties list and pay people to spend time developing on livedocs to implement the features which they require in livedocs for the benefit of the community.

Three weeks for the features which he wants? I think that if given the right team of people they could prob get it out the door in a month or two with the all bells and whistles and bugs ironed out.

PHP and CSS Cheat Sheet

The PHP Cheat Sheet and CSS Cheat Sheet are quick and easy to use quick references.

April 29, 2005

Code readability

Jim Winstead, Jr. brings up a point which deals with the subject of bad code readability which Neil has brought up previously.

It's the simple things like taking the time to make your programming easier. For example Jim shows us the following example:

$query = "SELECT id,name,url,rss,md5sum,method,updated AS up,"
         . "       UNIX_TIMESTAMP(lastchecked) AS lastchecked,"
         . "       UNIX_TIMESTAMP(updated) AS updated"
         . "  FROM blogs "
         . " WHERE updated > NOW() - INTERVAL 10 MINUTE AND method = 0"
         . " ORDER BY up DESC"
         . " LIMIT 10";

Which he goes onto mention that he is now doing it like:

$query= "SELECT id,name,url,rss,md5sum,method,updated AS up,
                  UNIX_TIMESTAMP(lastchecked) AS lastchecked,
                  UNIX_TIMESTAMP(updated) AS updated
             FROM blogs
            WHERE updated > NOW() - INTERVAL 10 MINUTE AND method = 0
            ORDER BY up DESC
            LIMIT 10
          ";

Which makes it easier to copy and paste into the mysql command line utility. I'm known for having extremely long lines of code for SQL queries when I was programming in PHP back in the day. Also in certain ways it can make it worse when you have long long lines which you are trying to debug and are unable to figure out quickly what your 900+ character SQL query is doing!

A line like:
$categories = $dbh->getall ("SELECT directory_company_category_map.company_id, directory_categories.id AS category_id, directory_sub_categories.id AS sub_category_id, directory_categories.category, directory_sub_categories.sub_category_name FROM directory_categories LEFT JOIN directory_sub_categories ON directory_sub_categories.category_id=directory_categories.id LEFT JOIN directory_company_category_map ON directory_company_category_map.category_id=directory_categories.id LEFT JOIN directory_companies ON directory_companies.id=directory_company_category_map.company_id WHERE directory_company_category_map.category_id=directory_categories.id AND directory_sub_categories.category_id=directory_categories.id AND directory_company_category_map.sub_category_id=directory_sub_categories.id AND directory_company_category_map.company_id='" . $listings[$i]['id'] . "'");

is quite a bit to process ;) It looks way better like:


<?php
$categories
= $dbh->getall ("
SELECT
    directory_company_category_map.company_id,
    directory_categories.id AS category_id,
    directory_sub_categories.id AS sub_category_id,
    directory_categories.category,
    directory_sub_categories.sub_category_name
FROM directory_categories
LEFT JOIN directory_sub_categories
    ON directory_sub_categories.category_id=directory_categories.id
LEFT JOIN directory_company_category_map
    ON directory_company_category_map.category_id=directory_categories.id
LEFT JOIN directory_companies
    ON directory_companies.id=directory_company_category_map.company_id
WHERE
    directory_company_category_map.category_id=directory_categories.id AND
    directory_sub_categories.category_id=directory_categories.id AND
    directory_company_category_map.sub_category_id=directory_sub_categories.id AND
    directory_company_category_map.company_id='"
. $listings[$i]['id'] . "'
"
);
?>

April 20, 2005

Robert Peake plans on writing a 'Farming PHP Series'

Robert Peake is planning on writing an article for the International PHP magazine on his experience of designing, buildign and implementing scalable web server farms for PHP/MySQL applications to give users an overview of issues involved.

I think one could wirte a whole series on this. I think his outline is too broad for a single article as there is quite a bit to cover with his suggested outline.

April 14, 2005

PHP 5 Power Programming

Via Derick:

"Our book PHP 5 Power Programming" is now available free of charge as part of the Bruce Perens' Open Source Series under the OPL. Enjoy! If you like it, consider buying the book to award it's authors though.

In this book, PHP 5's co-creator and two leading PHP developers show you how to make the most of PHP 5's industrial-strength enhancements in any project—no matter how large or complex. Their unique insights and realistic examples illuminate PHP 5's new object model, powerful design patterns, improved XML Web services support, and much more. Whether you're creating web applications, extensions, packages, or shell scripts—or migrating PHP 4 code—here are high-powered solutions you won't find anywhere else.

April 1, 2005

The PEAR Group announces that PEAR 1.4 is no more

PEAR 2.0 is being released about the 15 April 2005.

In an inofficial meeting the PEAR Group decided on the future of PEAR today. The main problem with PEAR is the BC topic and that therefore the migration of PEAR to PHP5 is pretty slow. To not be bound to their own rules, the PEAR community retired the release of PEAR 1.4 (which has been in alpha phase right now) in favor of starting a complete redesign for the PEAR installer which will be PEAR 2.0.

PHP.net announces new logo

Don't you just love the new PHP: Hypertext Preprocessor logo?

Egon Muenchberger is so far the only person to mail in about the fact that the logo has been changes so far on one my April Fools jokes. Pity my press release was not approved. :/

March 31, 2005

Random Python Notes

Coming from a PHP and Perl background sometimes using python can be a bit of a challenge when remembering what sort of array to use as python calls these dictionaries, tuples, or lists.

I've started compiling a random python notes and am planning on comparing various perl and perlism's with their equivalent python version.

March 30, 2005

Net_Monitor is out

Noticed that Net_Monitor 0.2.0 has is out and has support for sending SMS messages using Net_SMS. I'll release my patches for sending using SMS_Clickatell in a little bit.


API’s - SMS enable your website or application

Continue reading "Net_Monitor is out" »

March 29, 2005

PEAR Validate_ZA Released!

I've rolled the first beta release of Validate_ZA for the PEAR Validate package. I've submitted it to three people who are leads for the PEAR Validate package and they seem inclined to red tape the inclusion so I've posted the tarball online for download.

Download from here Validate_ZA-0.1.tgz.

You most likely want to install PEAR Validate first. Next up on the TODO list is getting the basic South African Identity Number validation implemented. Also drop me an email if you find the validation functions for South Africa useful or if you have any other suggestions.

March 25, 2005

Why Switch?

The Scobleizer found the following which I picked up via John:

FellowshipChurch.com has decided to switch from ASP.NET to PHP. Brian Bailey blogs about their switch:

    As we began evaluating our options, one of our developers moved to another department so we began to search for his replacement. As I evaluated the resumes we were receiving, I began to have the sense that we were continuing down the wrong path [in using .NET]. Here are the top ten factors that influenced the decision to change direction.

Jason Fried once upon a time said:

"It's all a matter of trust. If you don't trust your developer to choose the right environment, then how can you trust him to build the best application?"

March 4, 2005

SAJAX PHP Resources for developing AJAX Applications

There has been quite a bit of discussion relating to AJAX

Applications which use the AJAX logic includes Google's GMail, Google Maps, just to name two of the popular ones.

SAJAX is a tool which was developed to make programming websites using a AJAX framework – also known as XMLHTTPRequest or remote scripting – as easy as possible.

I can't await what else people are going to develop using cool JavaScript and CSS hackery.

February 12, 2005

Session Security

I've been reading up more and more about Session Security. I've even gone as far as starting a discussion on IRC to discuss certain aspects about session security, session fixation and session hijacking.

airox mentioned sending a second cookie for unencrypting the session data as session hijacking is impossible to stop.

For various projects I've been storing certain things like the user agent, remote ip address, etc. and comparing it. Also abusing session_regenerate_id() if someone passes ?session_name=session_identifier as a get / post.

Also one should not be saving session data to /tmp on the harddrive. I prefer storing session data in a MySQL database so that someone can't easily get to the session data.

February 11, 2005

Sean Coates has a blog

Sean Coates, from the PHP Documentation Team now has a blog.

Is PHP Enterprise Ready?

Every now and again people are asking the question "is PHP enterprise ready?"

Zend Technologies, who produce various products around PHP, list on their website that "Hewlett-Packard, Boeing, Lufthansa, Dresdner Bank, Disney Online, Yahoo!, Lycos, Sprint, T-Mobile, Orange, Nortel Networks, Lucent, WallStreetOnline and Siemens."

Here in South Africa big names like Independent Online, Clickatell, Itouch, the Internet Solution, certain South African Government websites, the University of Cape Town, Obsidian Systems just to name a few.

For example Clickatell sells SMS messaging via API's on their website where you can use their SMS gateway to send SMS messages to any local or international mobile phones. If you consider that Clickatell generate in excess than R5 million rands per annum and they use PHP for the scripting language to develop their web interfaces.

Independent Online use PHP for all their news portals including their flagship IOL site. Neil has discussed with numerous people about the IOL architecture and that it also runs on FreeBSD servers with MySQL for the database.

Continue reading "Is PHP Enterprise Ready?" »

January 31, 2005

PHP Security Consortium

Check out the PHP Security Consortium website for information on securing PHP applications.

January 29, 2005

Zend wakes up to smell the roses

From Chris which brings us back to the infamous I am Spartacus where sterling told everyone that he invented PHP4 after he read this article.

I must have missed the backlash this time, but I understand the scorn over Zend's marketing statements. In my opinion, the concern has more to do with the lack of credit given to Rasmus than anything else. When Rasmus is referenced as the creator of PHP, no one objects, nor do they seem to consider it to be hoarding credit from the many contributors to PHP.

Ask a mod_perl developer who created mod_perl, and they'll tell you Doug MacEachern. Ask them who the core mod_perl developers are now, and they'll name people like Stas Bekman and Geoff Young. Doug no longer contributes, but no one else can ever truly claim creation.

Andi and Zeev have made substantial contributions, and it's very likely that PHP would never have reached its current level of excellence without their early involvement. It is understandable for Zend to trumpet their founders' involvement with the language. However, I think there would be far fewer objections if Zend's marketing statements at least shared credit for the creation of the language. I personally think it makes sense for Zend to position itself as a company with key PHP creators and innovators as founders. We all know Andi and Zeev, and we know how substantial their involvement is. For the average company executive, however, they're lucky to have heard of PHP. Zend's marketing tries to make Andi and Zeev's roles sound as significant as they are.

I'm very glad to hear that they have intervened and will be toning down these statements. As for Zend calling itself "The PHP Company," I don't see a problem with that at all. It's no different than Xerox calling itself "The Document Company." It suggests a particular focus, and it's a marketing attempt to position itself as the only or paramount one of its kind. I could say I wrote "the book" on HTTP, and I think that's fine, even though there are others. :-)

But you have to remeber that Zend are making money from their innovations around the Zend Engine which they wrote with contributions from other developers.

Reminds me of back in the day Andi and Zeev decided to make the Zend Engine (which was a rewrite of the parser and extract it from the PHP core.):

Zend Temporary License
======================

This is a temporary license, that is in effect until the final Zend license is available.

* The final license will include the ability to distribute Zend freely, as a part of PHP (in both compiled and source code formats). It may (and probably will) allow to redistribute Zend under other circumstances as well, but at the very least, it'll be freely distributed as a part of PHP.

* The source code in the Zend engine is the property of Andi Gutmans and Zeev Suraski. Parts of this code are based on source code taken from PHP 3.0, which may include several patches and enhancements that weren't made by us (Andi&Zeev). If you're the author of such a patch and you're not willing to give up ownership over your patch to us, please contact us as soon as possible, so we can remove it. We're doing this so that we'd be eligible to sell the Zend engine for uses other than PHP, most notably - as an embedded part of possible commercial products that we'd have.

* Patches submitted to the Zend CVS automatically fall under this license, and by submitting them you're implicitly giving up your ownership over this patch to us.

* Until further notice, Zend is in a status of a closed beta test. That means that only people that were explicitly given the right to access the Zend CVS repository are allowed to use it. If you're reading this file and you weren't explicitly given the right to access the Zend CVS repository from either Andi Gutmans or Zeev Suraski - you're not supposed to have it - please erase the Zend files from your system. When the closed beta period finishes, the Zend CVS tree will be open for the public (in read-only mode, of course).

Any questions regarding Zend or this license should be addressed via Email to zend@zend.com.

It's understandable that they wanted to develop a spin off from prior work that they contributed to the PHP project (even though at that stage the code was released under the PHP License version 2 at the time).

Marketing would say lets over market Andi and Zeev's roles in the PHP community to make it sound like they actually did more than they did (which another marketer did when I was contracting for another company they made it sound like a was this uber uber php hacker that was a huge perl guru and what not at the time).

I don't go around releasing marketing material that says that because I've got karma to certain webbased projects of the PHP Project you know that I'm a good web developer?

I think I should stop rambling on about this subject again. It's also weird that Zend do a certification programme as well, which should not be run by them, but that is another story.

The PHP Credits do credit Andi Gutmans, Rasmus Lerdorf, and Zeev Suraski for "Language Design & Concept" which makes one belive that Zend's marketing statements are misleading.

John, who works for Zend, says on his blog that there has now been a change in Zend's internal policy:

Thanks to some complaining by influental PHP community members however, I'm pleased to announce that Zeev and Andi have intervened within the company and will from this point forward change the wording used in press releases to more accurately reflect the ongoing contributions to PHP by those in the general community. I get the warm fuzzies to see my employer willing to change their ways a little bit and give credit when credit is due! I'm told they'll also be changing the press release which caused the backlash on the web site soon as well.

January 18, 2005

Been testing Zend Canaveral

I've been testing the Zend Canaveral software for a week or so now. I spoke about Zend Canaveral in an earlier blog post.

It comes in quite useful for testing the PHP.net livedocs issues which appear in the event log like the following:

Quite useful :) Also I'm wondering is there any special deals for the PHP.net webteam so that we can utilise the software for developing stuff for PHP.net?

I'd be curious to know where the bottlenecks and problems are on various PHP.net websites.

January 14, 2005

Simpler solutions to forking software

We've been having discussions on IRC about the lack of development on the livedocs which is a "sub-project" of the PHP Documentation Team for creating "living documentation".

So instead of doing the whole forking thing that we've been chatting about for a few days on IRC, I'm getting karma so that I can start implementing various patches into the current code base as well as doing development work on livedocs.

January 7, 2005

Zend Platform a.k.a. Zend Canaveral is available

Via phpdeveloper.org

Zend have released their new Zend Platform, formerly known as Zend Canaveral.

Looks interesting non the less.

December 30, 2004

Thinking about the FUD surrounding the PHPbb exploit

I have been reading about PHP in the press and a comment from Jan Schneider.

I'm thinking the reason why people are assuming that the phpBB exploit would affect projects like Horde is due to them not understanding that the phpBB exploit was due to insecure programming. The Horde project was not vulnerable to the same vulnerability that phpBB was. We've always been reminded that we should never trust user data without validating the data. I call this "scrubbing the data".

I just wanted to pass along my concern about the beating that PHP is taking all over the press. Actually not just a beating, it's really being shit on, frankly. I've been looking around at all my usual large PHP sites, and not one word about the bad press, not even on phpBB. I'm amazed. I can only conclude that PHP people might be saying something like, "we put the patches out months ago and if people don't install them, then too bad, and we'll just wait 'til this blows over".

Why would we want to write press releases to state that because phpBB have included PHP in their project name it brings bad karma to the PHP project. In the License FAQ on the PHP.net website we state:

Q. I've written a project in PHP that I'm going to release as open source, and I'd like to call it PHPTransmogrifier. Is that OK?

A. We cannot really stop you from using PHP in the name of your project unless you include any code from the PHP distribution, in which case you would be violating the license. But we would really prefer if people would come up with their own names independent of the PHP name.

Why you ask? You are only trying to contribute to the PHP community. That may be true, but by using the PHP name you are explicitly linking your efforts to those of the entire PHP development community and the years of work that has gone into the PHP project. Every time a flaw is found in one of the thousands of applications out there that call themselves "PHP-Something" the negative karma that generates reflects unfairly on the entire PHP project. We had nothing to do with PHP-Nuke, for example, and every bugtraq posting on that says "PHP" in it. Your particular project may in fact be the greatest thing ever, but we have to be consistent in how we handle these requests and we honestly have no way of knowing whether your project is actually the greatest thing ever.

So, please, pick a name that stands on its own merits. If your stuff is good, it will not take long to establish a reputation for yourselves. Look at Zope, for example, that is a framework for Python that doesn't have Python in the name. Smarty as well doesn't have PHP in the name and does quite well.

I use Smarty for web-based applications which I've worked on in the past and IMHO I've found it to be the easiest template engine to work with.

For example I started developing an Application Framework a few months back and was thinking what do I name this framework. I thought about it for a while and asked a few friends about what they thought about a couple of names I came up with. I decided that I was not going to want to use PHP in the application name because of the karma isssue. Eventually I called it the Tshukudu Application Framework which means rhino in Sotho which is one of the official languages in South Africa.

The Horde Project is another example of a project who do not use PHP in their highly successfuly projects name.

That's fine, except then there's no response to all the disinformation out there. The non-tech-savvy sites are making it sound as though all PHP is susceptible to these attacks. I read enough to check on my version of PHP and what commands to look for in scripts, so I think I'm OK. I write scripts, and even I'm not completely sure.

Derick Rethans, another person from the PHP project, wrote up on his blog an entry about phpBB worm FUD which explains how the PHPbb exploit, the Santy.A worm, does not utilise any of the security issues addressed by the latest PHP bugfix release. It was due to a badly checked input variable which was passed to preg with the /e modifier. PHP also is vulnerable to other items addressed by the bugfix releases of PHP. They are incorrect on passing the blame to the PHP group and saying that it is not their fault. Trusting data from users without validating the data is the problem. Badly written PHP code can be exploitable in certain cases.

I remember when there was an exploit for earlier releases of phpBB which would allow non admin users to become admin users on your phpBB installation. I remember that was when I started looking around for another forum package which was written with security in mind. That was when I started using FUDforum.

Users don't either have not taken the time to learn how to code with security in mind for example turning register_globals which is a good start which reduces the likelyhood of someone injecting random data into your script which your script then uses. When register_globals are on it could even be possible to compromise settings in $_SESSION[] when the client requests a page from your site. For example you call a page like http://www.example.org/?_SESSION['auth']=1 when registered_globals is on it would set the $_SESSION['auth'] to 1. PHP Manual: register_globals explains this sort of attack more in detail.

FUDforum which has been developed by Ilia who one of the developers of the PHP language has written an the FUDforum wrote it with security in mind.

There are articles written to help users improve the way they write PHP code.

For example:

<?php
/**
* Bad code ahead!
*/

include ($_GET['page']);
?>

The above code snipbit basically allows people to pass unchecked data via the script to include a file. A better way of doing it would be:

<?php
$pages
= array (
    
'aboutus.php',
    
'contactus.php',
    
'nav.php'
);

if (
in_array($_GET['page'], $pages)) {
    include (
$_GET['page']);
} else {
    die (
"Fiddling.");
}
?>

I prefer not using doing inclusions like the above where you include files into your script. I find index.php?page=nav.php (a) looks ugly and (b) it's fine to have each file being seperate like nav.php which you would call normally.

Recommended Reading


December 29, 2004

Gotta 'love' Zend

Andi and Zeev's company is now listing info about people who have CVS access to the PHP cvs server.

jacques

December 25, 2004

Horde Installer (part 2)

Discussing earlier my work on my Horde Installer it is starting to look a tad easier to do now considering that the Horde Project is distributing a configuration utility alongside Horde where you can configure Horde via a web interface for the conf.php part. I'm going to see how difficult it is to add a web frontend to my setup-webmail.php script which currently runs via a command line script.

I'm thinking a good example of what a UI for the installer should be like would be the web based installer for gallery. We shall see how that goes. I'm going to get the command line script into a somewhat usable format for getting around to base the webbased installer version on but I don't think that using the Smarty template engine for templates for the installer would be a good idea as it would make the installer way too bloated.

December 24, 2004

Movable Type Comment And Trackback Closing Script (PHP)

I've hacked together a script which closes commenting and allowing trackback pings to blog entries that are older than 15 days. You can view it over here.

This is a early christmas present. It was written using PHP and PEAR DB (which should be in your include_path).

I was trying to get Kasia's perl based comment closing script to work but it did not and I was not in the mood for perl a few days ago and I hacked up the following php script.

It's been done by others before (Jeremy has it on his blog, mine is better cause it's longer!) but in the spirit of "not invented here" I wrote my own script which closes MT entries to comments and pings.

The idea is to cron it and forget about it and it has worked in that capacity well enough for the last few weeks.. so if anyone wants to use it (or they just like to amuse themselves by reading perl written by a Java programmer) the code is available here.

Remember you need to change the database connection details and you are good to do.

PHP FUD is getting annoying now

Picked up from Derick Rethans about PHP Fud which makes a better summary about this FUD about than I was typing.

Everybody who thinks that the Santy.A worm uses one of the security problems addressed in PHP's latest bugfix releases is wrong. It was NOT due to any bug in PHP, but merely a badly checked input variable which was passed to preg with the /e modifier. Besides this, phpBB is also vulnarable for some of the things address by PHP's new releases. But they are wrong saying that it is not their fault. Not-checked usage of serialized data is still their problem. Short version: use FUDforum.

I also use FUDforum ;)

November 20, 2004

We live in a cruel cruel world?

Rasmus has had his laptop stolen at a PHP conference in Paris.

My nice new T42p was stolen by some loser at a PHP conference in Paris. It is amazingly inconvenient to lose a laptop like this. It was from inside the conference hall and there was virtually no non-geek traffic there. If a fellow geek actually stole my laptop from a PHP conference then there is something seriously wrong with the world. You can steal my car, my money, my shoes, I don't really care, but don't steal my damn laptop!

Really sucks when someone steals your hardware.

November 16, 2004

Events Calendar Submissions

I must be the only one wondering why there are trolls who continously think that when they submit "events" using the event calendar that they are just going to automatically be added to the php.net website and the various mirrors of the website?

Am I missing something here? Or should I just assume that people can't read?

Have an upcoming PHP user group meeting? Holding a PHP training session? Submit your event here, and after it has been approved, it will be listed on the PHP.net homepage and appear in our full event listings.

November 10, 2004

doc.php.net

If doc.php.net looks half dead for the next twenty or so minutes it's due to an apache upgrade. It should be back to normal in a bit. :) I'm having to rebuild all the misc. apache modules etc. which I run on the webserver. Hopefully sqlite will behave after the upgrade :)

UPDATE:
Upgrade has been completed successfully and sqlite is working again.

November 2, 2004

Coding better PHP

I think numerous people who code using PHP have no clue how to utilise various excellent resources / add-ons for PHP from Smarty: template engine to using PEAR packages.

I've heard numerous times by various sources to not re-invent the wheel hence I started hacking up various application frameworks which I use on personal projects currently like my personal website.

I think reading the PHP manual is a place to start reading. I remember when I started coding PHP I used to read the source code to various websites from the PHP.net website to example files included with php2 and php3.

Other useful resources include:

I suppose we can always learn from various people and improve our usage of PHP. I try and utilise PEAR packages like PEAR DB which make it easier for others to see what I'm smoking or whatever that saying is when coding as well as reducing the time it takes on coding projects duplicating code. Sometimes one finds that you can extend a class like Net_Socket instead of starting your own one from scratch.

October 18, 2004

upgrading your sources before going offline

One of the problems with the pricing of telephone calls in South Africa is that one tends to need to fit all your downloading in when you are either at the office or when at home and on dial-up you need to limit your time online.

Here is some code which I use to update all my cvs checkouts from cvs.php.net for working offline and works like a bomb. :)

October 11, 2004

Zend Mugs get delivered broken

*sigh* I received a Zend Mug which arrived broken on Saturday. Handle is off. There is a nice couple of chips in the cup. Best of all the people who were packaging the mugs forgot the following important important points for packaging that you need to put bugs into a box which helps keep the mug in one piece when shipping!

I might take some photos of the broken mug to place online when I get round to it. As Don says it makes a nice pencil holder. *sigh*

September 27, 2004

PHP 5.0.2 is out

php-version5.gifThe PHP Development Team is proud to announce the immediate release of PHP 5.0.2. This is a maintenance release that in addition to many non-critical bug fixes, addresses a problem with GPC input processing. All Users of PHP 5 are encouraged to upgrade to this release as soon as possible.

For changes since PHP 5.0.1, please consult the ChangeLog.

PHP 4.3.9 is out

php-version4.gif The PHP Development Team is proud to announce the immediate release of PHP 4.3.9. This is a maintenance release that in addition to over 50 non-critical bug fixes, addresses a problem with GPC input processing. This release also re-introduces ability to write GIF images via the bundled GD extension. All Users of PHP are encouraged to upgrade to this release as soon as possible.

For changes since PHP 4.3.8, please consult the ChangeLog.

September 14, 2004

Can't wait for PHP 4.3.9 :)

php-version4.gifI can't wait for the long awaited release of PHP4 version 4.3.9 which fixes numerous bugs and is more stable than 4.3.8 from various tests I've been doing.

There is less output on the failed test summary section which is a good thing if you ask me ;) I think this is going to be the best PHP 4 release yet. Hats off to Ilia our PHP 4 release manager.

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Bug #24773 (unset() of integers treated as arrays causes a crash) [tests/lang/bug24773.phpt]
Bug #24783 ($key not binary safe in "foreach($arr as $key => $val)") [tests/lang/bug24783.phpt]
Bug #25547 (error_handler and array index with function call) [tests/lang/bug25547.phpt]
Bug #27731 (error_reporing() call inside @ block does not work correctly) [tests/lang/bug27731.phpt]
Bug #27780 (strtotime(+1 xxx) returns a wrong date/time) [ext/standard/tests/time/bug27780.phpt]
xslt_set_object function [ext/xslt/tests/xslt_set_object.phpt]
=====================================================================

September 13, 2004

php vs. perl for web development

Via Jim Winstead Jr.

joe johnston explains why php is more popular than mod_perl for web development. the short answer is that they solve different problems.

i've been thinking about this with regard to python recently. i'd love to learn more python, and use it in the web space, but mod_python is more like mod_perl than php, and when i'm developing web stuff, my thinking is matches the php model closer than the mod_(python|perl) model.

Also remember that we should try and use the best tool for the job. In most cases for myself it is using PHP.

September 11, 2004

doc.php.net

doc.php.net for the PHP.net documentation types is up and running. There are various utilities available for us which Gabor suggested we get working on our vhost.

We have both an MySQL database and SQLite database running for our requirements.

September 2, 2004

Livedocs

Spent a couple of minutes quickly creating a page header image for the livedocs patch system which goes in with the theme of the main site layout. I will eventually get around to hacking up the blog layout at some stage.

August 29, 2004

Cache_Memcached Hacking

Been hacking on Cache_Memcached to try and get the perl and php versions to return similar data for their _hashfunc function.

In Cache/Memcached.pm there is the following:

sub _hashfunc {
    return (crc32(shift) >> 16) & 0x7fff;
}

and in the php version I have

<?php
function _hashfunc ($_num) {
    return (
sprintf("%u", crc32($_num) >> 16) & 0x7fff);
}

Now my question is why do they return the same hash in certain cases and in other cases different hashes? Or was I being silly when porting the perl code to PHP?

Update
Figured it out. :)

August 27, 2004

Auth_TypeKey

I was speaking earlier about writing a PECL module for the TypeKey Authentication Service which would work similar to Benjamin Trott's Autehn::Typekey PERL module.

One of the things which I like about the TypeKey Authentication Service is that users register on the TypeKey website and are required to be logged into the TypeKey website prior to them trying to post to my webblog or to any other webblogs which requires you to have a TypeKey profile.

Another factor in this approach has reduced Comment Spam, but the Comment Spammers then decided to use trackback Spam, so you have to install some sort of blacklisting system to compliment your comment spam prevension methods.

Continue reading "Auth_TypeKey" »

Document your code

Paul M. Jones has been complaining about public PHP code esp. PEAR Classes.

Continue reading "Document your code" »

Mirmon is nifty

I've been using Mirmon for a couple of weeks now to monitor the PHP website and the various mirror sites of www.php.net to see how fresh content on the mirrors are, whether there are problems with mirrors updating using rsync, and various other useful statistical data one gets back from mirmon's web status output.

August 19, 2004

Typekey Authentication for PHP

Benjamin Trott released Authen::Typekey for Perl which I was thinking about how cool it would be for having a PEAR class which similar to the Perl version.

Doing some browsing online I've come across TK 0.1 which requires one to load an additional module to have access to the DSA stuff.

August 17, 2004

livedocs patch system

Started hacking up something which I'm currently calling the Livedocs Patch System in it's current form. Basically what this patch system does is allows users to submit patches for Livedocs via a web interface where we can see the patches.

I'm thinking of adding additional functionality to comment on patches, possibly vote on a patch.

I might even hack up a bug tracker for livedocs as well.

August 13, 2004

PHP 5.0.1 is out

php-version5.gif
For those who have not heard yet that PHP 5.0.1 has been released!

The PHP Development Team would like to announce the immediate availability of PHP 5.0.1. This is a maintenance release that in addition to many non-critical bug fixes also includes new UNIX and Windows installation docs which are now auto-generated from the PHP Manual.

For changes since PHP 5.0.0, please consult the ChangeLog.

August 6, 2004

Making docweb happen

Sometimes the only way forward for when things start slowing down is to make them happen.

docs.php.mirrors.powertrip.co.za is where I've started making the PHP Documentation Site 'live' for heavy development.

Things I'm currently focusing on at the moment is getting the various scripts in docweb/scripts to work on the box so that we can get the web interface back on track.

August 5, 2004

php.net website bugfixing time

Okay yesterday I've fixed an issue where the links for the references of messages on news.php.net which was not working. Also it does not show references where colobus (nntp server written in perl that serves up ezmlm mailing lists as newsgroups coded by Jim Winstead) does not know anything about that particular message-id.

If anyone finds any issues which needs to be resolved, please report the bugs to PHP.net bugs interface and we will get round to sorting them out.

I'm planning on looking into getting the news.php.net website to display threads for messages show which message in a thread you are currently viewing, show list descriptions on the frontpage to the news site.

July 25, 2004

Hardened PHP + Zend Optimizer = Segmentation fault (core dumped)

Running php 4.3.8 with the hardened-php patch 0.2.2 and ZendOptimizer 2.5.3 one gets the following:

su-2.05b# php -v
Segmentation fault (core dumped)

Not very nice :/

Update:
It turns out that Zend Optimizer directly access the LLists instead of using the Zend Engine API. Busy waiting for feedback from Zend as to when they are going to fix this. Dmitry Stogov who works for Zend wrote Turck MMCache prior to joining Zend. Turck MMCache works when Zend Optimizer does not. IONCube is reported to also work.

July 21, 2004

What do BFN and MFH stand for?

Today, two seperate users asked on the php internals mailing list what does BFN and MFH stand for.

BFN stands for 'Bug Fixing News'. This is essentially when someone fixes a bug in php. Normally this relates to a bug filed on the PHP bugs website.

MFH stands for 'Merged From HEAD'. HEAD is the main development branch and when features / bug fixes get applied or merged to other branches it's called MFH.

More reason to code using 'english'

In PHP we have some weirdly named things. For example there is Paamayim Nekudotayim which at first looks like an extremely weird choice for calling a double colon. At the time of writing Zend Engine 0.5 Andi and Zeev decided to call the double colon the Paamayim Nekudotayim and the name has never changed. Paamayim Nekudotayim actually means double colon in Hebrew.

Just imagine if when I code if I named everything in Afrikaans we might end up with things variables and functions like $_naam, $_tyd etc. A scarey thought, although I prefer coding with names in English as it makes it alot easier for others to read variable names, etc. and normally English is the bulk of people's second language if not first.

Continue reading "More reason to code using 'english'" »

PEAR Archive_Tar

I talked a little about my Zend Optimizer Download Script which currently just downloads the latest version of Zend Optimizer from Zend Technologies website.

I've been thinking about adding some code to basically make it extract and install Zend Optimizer in the normal way I've been manually installing Zend Optimizer for the past couple of years.

I've used Archive_Tar previously for my Horde Webmail Solution installation via command line which works well except for the fact you still have to manually configure certain bits and pieces of the Horde suite.

July 14, 2004

PHP 4.3.8 released!

php-version4.gif
Version 4.3.8 of PHP has been released. This has release has been made in response to several security issues that has been discovered since the 4.3.7 release of PHP. All users of PHP are strongly encouraged to upgrade to PHP 4.3.8 as soon as possible.

June 16, 2004

IOL's website looks changed

Went to take a look at IOL today, and found that they've changed their look and feel. And on top of it I keep getting a server busy page for the past hour.

The look looks a lot cleaner, but time will tell once they fix their server load issues if the look extends through the entire site.

Continue reading "IOL's website looks changed" »

June 12, 2004

search.php.net

Busy hacking some php to re-introduce the useful old php.net website search functionality. Google results seems to not give me what I want like the old site serach using htdig did.

The idea would be to perhaps make the site search scale over a couple of boxes using the same generated htdig databases etc.

/usr/local/bin/htdig -a -s -c /usr/local/etc/htdig/php.conf

June 11, 2004

PHP 5.0.0RC3

php-version5.gif


The third (and hopefully final) Release Candidate of PHP 5 is now available! This mostly bug fix release improves PHP 5's stability and irons out some of the remaining issues before PHP 5 can be deemed release quality. Everyone is now encouraged to start playing with it!

Busy testing PHP 5.0.0RC3 with a couple of production applications to iron out any migration problems for when we upgrade to PHP 5.0.0 in the near future once it is released.

March 8, 2004

PEAR Net::SMS

Busy getting ready to role version 0.2 of the PEAR Net::SMS package as part of a project to code classes for interfacing to various SMS gateways.

Continue reading "PEAR Net::SMS" »

June 24, 2003

Zend sponsors PHP Usage Survey

Zend Technologies is sponsoring a public PHP Usage Survey. The results will be shared with the PHP Group, and will help us to better understand the ways in which PHP is being used, and what may need improvement. Fill it out and get a chance to win one of 50 PHP T-shirts!

Continue reading "Zend sponsors PHP Usage Survey" »

Afrigator