Archive for November, 2007

WAMP server

November 12, 2007

“WAMP” stands for “Windows-Apache-MySQL-php”, and the WAMP server is a one-stop installation package. It’s far far easier than downloading and installing Apache, MySQL and php individually – take my word for it, I did it the hard way for years and wouldn’t go back. It’s great for development, you can develop on your own machine without troubling your internet connection or worrying about debug messages appearing on a live site. Don’t listen to people who say “if you’re gonna deploy on Linux you need to develop on Linux” – it just isn’t true, or, rather, the advantages outweigh the disadvantages (just make sure your editor is set to produce unix-style line endings).

php script returns blank page

November 12, 2007

A common thing you see reported on php forums is someone tries to do something, and just gets a blank page. Has happened to me a few times, and puzzled me at first, but usually the problem is a fatal error in your code where error reporting is turned off in the server (recommended behaviour for live servers), so the page just returns blank.

Makes the code damn hard to debug, but sometimes you can get at the error log – make a file with the function phpinfo() in it and it’ll tell you where the error log is, if you have shell access to the server you can go in and take a look. If you don’t … well, you’re supposed to be able to change the error reporting settings within a script using ini_set() or error_reporting() but that hasn’t worked for me in the past. Obviously it helps if you’re doing your development on a development server where you can change the error settings on the server itself – if you’re not, you should be, WAMP is a breeze to set up on your desktop and it makes your life much easier – but even when something works fine locally you can get problems when you go live … if that happens you’ve no option but to just try and figure it out without any error messages.

Project Pier

November 7, 2007

Been working on a work collaboration system for the last few days, and I’ve been using Project Pier, a Honest Public Licence fork of ActiveCollab. I’m adding a module to deal with events (meetings and the like), and the code is a delight to work with – it’s all MVC, and very easy to find your way around.

Open-source CMSs revisited

November 7, 2007

I’ve calmed down a bit since the other day, my frustration with MODx was bringing every difficult project involving hacking an off-the-shelf product back to me. In fairness to osCommerce, if you don’t want a radical re-skin or lots of enhanced functionality, it is a breeze to use – it’s just that I only get called in when major surgery is required, so I guess my perspective is kinda skewed, like a cop who thinks everyone is a criminal or some such.
And I did have a fairly good experience with CMS Made Simple lately, I added a shopping cart to it with a minimum of fuss.

Off-the-shelf CMSs etc

November 5, 2007

Sometimes I wonder whether the time and effort I’ve put into learning how to bend these things to my will is worth it. I’ve used osCommerce, joomla, CMS made simple and MODx and almost every time I’ve wondered whether I wouldn’t have been better off writing the system from scratch. Especially if there’s a lot of skinning involved.

Currently I’m trying to get MODx to serve fairly simple mobile content and so far I’ve found it to be far more flexible than, say, joomla, but nowhere near as easy to use as plain php. A simple search page that would have taken me a short time to write if I’d rolled my own CMS took me ages to implement using the MODx HyperFlexSearchForm snippet – partly because I had to figure out how snippets work in MODx and partly because it was a bit buggy (see my forum post on http://modxcms.com/forums/index.php/topic,5867.60.html). Even within the MODx framework I probably could have written my own search snippet in less time than it took me to figure out the supplied one.

The real rationale for using a CMS/CMF is that someone else (especially a non-expert coder) can come along afterwards and easily make modifications … but it never is easy is it? Perhaps they’re good at preventing the seemingly inevitable spaghetti-ising of code that passes through many developers’ hands – I don’t know, osCommerce certainly isn’t, but maybe the CMF approach of MODx will be better, too early to tell. I make such a meal out of figuring these systems out though that I expect other people will too, and they might have an easier time just figuring out well-written straight php code.

And the admin interface in the off-the-shelf CMSs is always so cluttered, but that’s a whole other issue.

Confirm order after paypal payment

November 2, 2007

The last time I did a site with payment via paypal was in 2005, and because of paypal’s flow at the time most orders were unconfirmed. It goes like this – user puts stuff in cart, clicks checkout, goes to paypal, pays, and then sees a screen saying “Your payment is complete. Click here to return to merchant’s site”. Most people don’t bother to make that final click, so I couldn’t confirm that the order had been paid for.

Maybe I missed this back in 2005, but I was doing another site yesterday and came across a parameter called “notify_url” you pass in the POST vars to paypal. It’s a url that paypal calls when the payment goes through, so I was able to use that to confirm the order had been paid for, without the user having to return to the merchant’s site after payment. Very handy

osCommerce payment error with realex

November 1, 2007

Came across this one yesterday – was using the Realex payment gateway with osCommerce, and after the transaction was processed was getting this message “Your transaction has been successful but there was a problem connecting back to the merchant’s web site. Please contact the merchant and advise them that you received this error message. Thank you.”.

Fixed the problem in the end by setting SESSION_FORCE_COOKIE_USE to ‘false’ in the configuration table in the database. Here’s what was wrong:

Here’s a quick rundown of how Realex works (or rather, how “Realex redirect” works, they have other services that involve xml messaging) with osCommerce – the page checkout_confirmation.php has a payment button that is a form submit, and that submits various fields by POST to the realex server. The user sees a page where they enter their credit card details, if the card validates the realex server calls a success page on the merchant’s server and displays it.

Called Realex and they told me that their application, on requesting the success page, was receiving a http 302 header (a redirect) instead of a normal http 200 header followed by a page. It doesn’t accept redirects, and so it was displaying the error message. The 302 was redirecting to a login page, which suggested that the session wasn’t being maintained – verified this with a test page.

Thought about it and realised that because the success page was being requested from realex and not from the user’s browser the session cookie wasn’t being sent. No matter, I could see in the code that the session should be restored from a session id in the http POST vars if it was there, and I could see that the session id WAS being sent in the POST vars in the request from realex. Closer inspection of the code revealed the SESSION_FORCE_COOKIE_USE config variable, which was preventing it … so I changed it in the database and hooray!