Install the MSSQL module for PHP on CentOS 5

Unfortunately there is no pre-built module/extension for MSSQL for PHP in the Yum repositories for CentOS 5, so you need to build it yourself. It’s a reasonably simple process, but you do need to have gcc and php-devel packages already installed (and a whole bunch of others which I’ll list at the end of this post).

Categories PHP

Determine whether PHP is being run via HTTP or CLI

PHP can be run as a webserver module, as a CGI application or from the command line as a CLI script. There is both a function and a PHP constant which allows you to determine whether PHP is being run via HTTP or CLI. This post looks at the function and constant and the possible values, as determined in the PHP 5.2.5 source code.

Categories PHP

PHP Register Long Arrays HTTP_POST_VARS

I have been in the process of moving my websites from a dedicated machine running Gentoo Linux to a VPS (Virtual Private Server) running CentOS 5. One of the ecommerce websites uses an old install of osCommerce which expects register globals and register_long_arrays on, otherwise things won’t work very well.

While testing the site out on the new server, I couldn’t work out why some of the form posts were working and some weren’t. For example, on some pages I could add items to the shopping cart but on others I couldn’t. I also couldn’t click the form button to proceed to th checkout or update my basket: whenever I tried it kept showing me the same basket page again.

Categories PHP

Replacing relative URLs with absolute URLs in PHP

I’ve finally set up an RSS feed for this site and one of the things I needed to sort out was the use of URLs and image tags. All the anchor tags in this site are relative, and so are all the image sources. This isn’t going to work in an RSS feed because it would mean none of the links would work, and the images would all be broken. Fortunately this is easy to fix with the use of PHP’s string replacement functions.

Categories PHP

PHP Magic Constants

There are several PHP "magic constants" (or "magical contants") which can be useful for a variety of reasons. These magic constants aren’t actually constants at all, but effectively behave like them, although the values change depending on the context.

Categories PHP