Archive for the 'Web' Category

Big PHP Niggle

Friday, June 20th, 2008

I need a quick bitch.

I love PHP. It’s everywhere. All my sites are written in it. My CMS is written in it. My blog engines, Wordpress and b2evolution, are written in it. It’s free. It runs on any platform. Hosts all support it. With PHP 5 they’ve even done a lot of work on PHP4’s main downfall - lack of OOP support.

One thing really pisses me off though - it’s totally inconsistent.  Consider these two functions:

  1. strstr — Find first occurrence of a string
  2. in_array — Checks if a value exists in an array

Take a close look. See the signatures?

string strstr ( string $haystack , mixed $needle [, bool $before_needle ] )
bool in_array ( mixed $needle , array $haystack [, bool $strict ] )

In in_array the first parameter is what you’re looking for and the second is what you’re looking in (more or less consistent with preg_match).  In strstr (and its derivatives) this order is reversed. Who on Earth let that slip through? I’m yet to find a free text editor that will tell you which parameters a given function expects (Dreamweaver does a decent job but it’s bloody expensive for a text editor!) the way Visual Studio does for C#, which I use a lot in work.  Given that situation, you’d expect consistency in this sort of thing.  Apparently not so. Instead, every time I want to use one of these functions I have to do a quick Google to bring me to the PHP manual page to tell me which order the parameters come in.

Of course they can’t even fix that without breaking backwards compatibility either, so we’re probably stuck with it.  Bloody marvellous!

Add This

Firefox 3 - Initial Impressions

Thursday, June 19th, 2008

I haven’t come across anything truly groundbreaking in Firefox 3, possibly because I’ve become accustomed to much of the feature set through the Betas and RCs, but there are one or two improvements that are quite useful (as well as a couple of regressions unfortunately).

Wee Niggles

First the bad. When you view Page Info from the context menu it doesn’t give a link to the CSS file in the Media tab any more. I was sure it was there in 2 and a quick google confirmed this. This really sucks - I can’t see why they’ve taken it out.

Secondly, when I was looking through the options to try and return the aforementioned CSS links, I discovered Firefox had decided it was going to automatically download any future updates when they were discovered (I promptly switched the option to “Ask me…”). Bad Firefox.

Magic Address Bar

The good is good though. It doesn’t seem like it at first, but to my mind the biggest improvement of all is the address bar. Sure they’ve added a “Most Visited” folder to your bookmarks toolbar which (shockingly, given the title) contains a list of the sites you visit most frequently, but the address bar has some great, if not immediately obvious, usability improvements.

(more…)

Add This

FireFox 3 Released Today

Tuesday, June 17th, 2008

Looks like the excitement is a little bit premature. Not just yet, but at 6pm BST the newest version of Mozilla’s FireFox web browser will be released. Mozilla want Firefox 3 to break the record for the most downloads in 24 hours, which begs the question as to why they pissed off Australasia and half of Asia by promoting Download Day as today, 17th June, when they’re not making the new version available until 10am Pacific Time which means the aforementioned regions will not see the download released until it is 18th June there. That’s without even considering yours truly and millions of other Europeans who will be finished their days work.

Good work Mozilla.

Add This

Solved: New WAMP Install Won’t Parse PHP

Wednesday, May 7th, 2008

I spent ages trying to figure out why my new installation of WAMP Server 2 wouldn’t parse my PHP and was spitting it out exactly as-is in the source file. I hoked around in the VirtualHost configuration, because the PHPMyAdmin that comes with WAMP Server was working fine so it had to be something wrong in the VirtualHost that I just configured that was stopping .php files being sent to the PHP parser, yes? No.

As it turns out, it’s much simpler than that. Apache was sending the file to PHP to be parsed, by PHP was ignoring my code. Why? WAMP Server 2 comes with “short open tags” turned off (this may be a general PHP or PHP 5 thing, though not sure). Click WAMP -> PHP -> php.ini to edit the aforementioned file and find the line:

short_open_tag = Off

Replace Off with On et voila.

The ‘more correct’ though long-winded solution is to replace all your <? opening tags with <?php if you’re really keen (though that’ll also mean replacing <?= with <? echo). Me, I think I like my short tags.

Add This

WordPress / Fantastico Server Move

Wednesday, May 7th, 2008

I recently moved this site to a new host because of ongoing problems with my previous hosts. Thanks to some intermittent database errors I’d decided it would be prudent to do my first backup in some time at the start of last week. By the end of that week they’d deleted my account, so I suppose I should be grateful their database server was so f**ked. Nevertheless, the move caused a few issues when my new hosts told me the complete backup I uploaded to them was corrupt. I can only assume (because some backups were corrupt and others weren’t) that it was due either to encrypting the archives using AES in Winzip or decrypting them in 7zip.

Anyway, that meant manually creating the accounts, setting up the mail accounts and subdomains in them, extracting the root folders (public_html, mail etc) individually and manually importing the SQL backup. Everything was relatively painless (if dull) however Fantastico wouldn’t recognise my Wordpress installations (I had two). To persuade Fantastico that there really were a couple of WordPress blogs I had to do two things:

  1. Extract the \.fantasticodata\WordPress files from the zip (in this case it was called nerd.steveferson.com| ) and upload it to the same location in the FTP server. Of course that bar | made Windows barf, so you’d need to rename it (e.g. using an underscore instead) and replace the bar after uploading it via the FTP client (FileZilla didn’t seem to have a problem doing this).
  2. I think this is might be because the blog’s in the root of a subdomain, but I also had to upload a file called installed_in_root.php from \.fantasticodata to that location on the server.

Once I did this, Fantastico picked up the blog and allowed me to upgrade WordPress to 2.5.1 - no hassle.

Add This

I Can Has Vista Sidebar Gadget?

Monday, April 28th, 2008

O hai!

I hart lolcatz.

I hart lolcatz so much dat wun dai I thoughted “I can has lolcatz wen I makes teh pooter turn on?” So I maded a Vista gadjit an now I has new lolcatz every dai.

If u hart lolcatz liek mee an wants lolcatz in ur pooter makin u laff, downlodes mah gadjit. I has tested it 4 liek rly long time. It rly works, srsly. An evry1 needses moar lolcatz.

Kthxbai.

(more…)

Add This

More aspnet_regiis Goodness - this time on Vista

Friday, April 18th, 2008

Some time ago I published a blog describing the use of a command line tool called aspnet_regiis.exe to overcome a “Server Application Unavailable” message when I was trying to get ASP.NET working on IIS 6 on Windows XP.

Just now I’ve used the same tool to fix a similar (I think) problem on IIS7 on Vista. I was trying to get some practice with ASP.NET. I’ve already got IIS7 and I’ve already got the .NET Framework 2.0 installed. However it seemed, again, that IIS wasn’t aware of the Framework’s existence. When I tried to browse to a simple Hello World page I was greeted with an HTTP 404 (404.3 to be precise) informing me that:

“The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.”

Despite the different error messages it appeared to be a similar problem. Apparently it was. That wonderful little solution again:

  1. Start -> Cmd
  2. Navigate to your .NET Framework directory (e.g. C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727)
  3. Run the command “aspnet_regiis.exe -i”
  4. Wait…
Add This

Solved: Wordpress Admin Images Missing

Friday, April 11th, 2008

I upgraded this blog to Wordpress 2.5 today, and installed a new copy of Wordpress on a subdomain too. Both these actions were carried out using cPanel & Fantastico.

When I logged into the backend of the new subdomain there were no images - including no buttons on the rich-text editor (TinyMCE) and no Wordpress logo on the login screen.  I later noticed there were also background images missing on the public part of the new blog.  When I right clicked “View background image” on the missing image, it took me to an HTTP 403 (Forbidden) meaning there was a permissions problem. The strange thing was the problem didn’t occur in the nerd. backend.

And the solution…? In this instance it was because I’d enabled hotlink protection in my server to stop other people using images stored at steveferson.com on their sites, because this eats up precious bandwidth.  When I created this new subdomain, I had forgotten about the hotlink protection and so hadn’t added it to the list of sites allowed to link to images at SteveFerson.com.  When I added it everything went back to working as expected.

Add This

Solved: Comments Disappeared / Error after Wordpress Upgrade

Tuesday, January 22nd, 2008

I’ve just upgraded a Wordpress blog to the latest version 2.3.2 and when I went to write a new post I realised all my categories had disappeared. They were still in the database but the list to the right of where you type your posts was empty. As well as this, I noticed that adding new comments was giving a 404 error in the middle of the page. This second issue was reminiscent of another one I had (and solved) upgrading to 2.2 - the errors were actually 403 errors, but redirecting to 404 error pages because there was no 403 error page defined (i.e. the 404 was happening when the server looked for the 403 page).

I noticed a file called error_log (no extension) in the wp-admin directory and had a look. Apparently some database tables (’wp_term_taxonomy’ and ‘.wp_terms’) were missing. After reading this support thread I investigated the possibility that my database was out of date. I followed MichaelH’s suggestion of navigating to /wp-admin/upgrade.php, which informed me that my database was up to date. I didn’t believe this to be true though; certainly not after learning that tables were missing. At a hunch, I guessed that when I’d been upgrading through Fantastico, I must have run out of space (a semi-regular occurrence) so the database upgrade was probably left half finished. Assuming that Wordpress would determine whether or not I needed to upgrade based on a single configuration or database field I soon found the wp_option.db_version field, which was set 6124.

The Solution

As I suspected, 6124 is the db_version value for Wordpress 2.3. I changed this field’s value back from 6124 to 5183 (the db_version value in Wordpress 2.2) and hit the upgrade.php page again. This time it told me to upgrade, I did, and the categories are back.  Adding new categories still caused 403 and 404 errors, but that was because I’d deleted the .htaccess file created previously when trying to fix the first problem! Recreate that and we’re cooking with gas again.

Add This

ACT - SessionID and Login Problems With ASP .NET 2.0

Friday, September 14th, 2007

I recently encountered a problem with Microsoft’s ACT (part of Visual Studio 2003) when testing a web service by emulating a browser-based client. For posterity’s sake, here’s an overview of the problem and, more importantly, the solution.

Background
Using Application Center Test (ACT) to help automate performance testing designed to compare the performance of a web service running on ASP .NET 1.1 with ASP .NET 2.0.

Problem
Originally .NET 2.0 seemed to be performing many times better than .NET 1.1, but it was soon discovered that when running .NET 2.0, ATC was receiving a lot of 302 errors on 2.0 which it wasn’t on 1.0. On further investigation the Web Service wasn’t actually making all the correct database calls and on installing HTTP Monitor, it became apparent that the login wasn’t working. When I recorded the test using Internet Explorer 7, the HTTP requests worked as expected, however when ATC repeated them it was not returning the ASP.NET_SessionID.

(more…)

Add This