Tag Archives: PHP

PHP 4, WordPress 2.5 and BBPress 0.9

I just found a bug in WordPress 2.5, which is exposed when it is run in PHP 4.3.11. I thought of detailing about it here so that it will be useful for others who are seeking solution for the similar problem.

Recently I was trying to integrate WordPress and BBPress to make them share a single database and cookie. The advantage of this integration is that a logged in user can share the session between WordPress and BBPress.

Right now the latest version of BBPress is 0.9 and it can be integrated only with WordPress 2.5. Only BBPress 1.0 (which is in alpha) can be integrated with WordPress 2.7. There is an excellent tutorial by _ck_ which explains the reasons behind this and it also has a step by step guide to integrate them.

I tested this integration in my test server running PHP 5 and was able to do it within minutes. But when I tried to do it in another server running PHP 4.3.11, it was not working. After lot of head banging and hair picking, I found out that there is a bug in WordPress 2.5, which does not allow you to share the cookie with BBPress 0.9 under PHP 4.

The following is the technical detail about the bug. If you are not technically inclined, you can safely skip it. You only need to remember that you cannot integrate WordPress 2.5 and BBPress 0.9 in PHP 4, you have to use WordPress 2.5.1

Well for the brave hearts here is the explanation. 🙂

In both WordPress and BBPress, the function wp_hash() is used to generate the hash, which is required to encrypt the cookie.

In WordPress 2.5, the function wp_hash() is defined in wp-includes/pluggable.php file as

function wp_hash($data) {
    $salt = wp_salt();

    if ( function_exists('hash_hmac') ) {
        return hash_hmac('md5', $data, $salt);
    } else {
        return md5($data . $salt);
    }
}

It checks whether the function hash_hmac()is present. If not it generates the hash using the function md5(). The problem is that hash_hmac() is present only in PHP 5 and WordPress includes a copy of hash_hmac() function in the wp-includes/compat.php file for backward compatibility.

But in BBPress, wp_hash() function is defined in bb-includes/pluggable.php as

function wp_hash($data) {
    $salt = wp_salt();

    return hash_hmac('md5', $data, $salt);
}

This bug is present in WordPress 2.5 and will only affect servers running PHP 4. So if you are running PHP 4 and want to integrate WordPress and BBPress, then you have to use WordPress 2.5.1 and not 2.5.

Hope this explanation saves some hair for someone somewhere, doing something similar. 🙂

Posted in WordPress | Tagged , , , | 1 Comment

What is your IDE?

My post on my love with Java has sparked a mild IDE war in the comments section. So I thought of sharing my thoughts on using an IDE.

I have used just simple text editors like vi, notepad, textpad to full grown IDE’s like Zend, IntelliJ IDEA etc. (Well I know that some of you are going to accuse me for calling vi has just a simple text editor 😉 ) and my answer to the question, “Whether you need an IDE?” is surely YES. I have worked under people who think that using an IDE is overkill and distracting but personally my view is that if you are going to do the same task more than twice a day then your IDE should do it. But at the same time I do respect people’s view that an IDE should be simple to use and not bloated and too heavy on the machine. After all you are going to spend most of your time with it and if it’s too slow then you productivity is under danger.

When ever I get a chance to meet a person working as a web developer one of my first questions to them would be, “What IDE are you using?” and believe it or not it is worse than the question “Which religion do you follow?” and have fought/witnessed soo many IDE wars. 😉

So if you ask me what my favorite is, For Java I mainly use IntelliJ IDEA and I simply love its refactoring, debugging and navigation support. I can go to any method/class/file with just a few keystrokes. I also love its code folding and its support for Javascript and CSS.

But for PHP I should rather admit that I am still in the search of a one with all the features I need. I use Zend mostly and love its debugging and syntax support but miss code folding (For HTML) and support for Javascript and CSS.

Recently I came across Aptana and it looks really promising. It has built-in support for both Javascript and HTML/CSS. If they could add support for PHP (which they say is coming soon) I am sold.

So guys, tell me “What IDE you use?” and what is your favorite feature?

Posted in Web Programming | Tagged , , , | 13 Comments

PHP eLearning

One of my friend refered me to this excellent eLearning for PHP

Try it out if you are also willing to learn PHP like me 😉

Posted in Web Programming | Tagged | Leave a comment

PHP MVC Framework

Just strumbled upon this when I was searching for some good frameworks to be used with PHP for my official work.

Check out php MVC The Model View Controller (MVC) Framework for PHP Web Applications.

It is similar to Jakarta Struts which is the famous framework for Java web applications

Posted in Web Programming | Tagged , , | 1 Comment