Monday, March 30, 2009

Could Not Modify Header Information - A Wordpress Experience.

I've been playing with Wordpress as a CMS project recently and came across an interesting "semi-bug(let)" that took ages to resolve, but was rather simple in the end.

A white screen.

Attempting to login to my admin screen after being logged out after a connection dropout gave me a blank screen, nothing on view-source: and no errors in the Apache logfile.

Googling for the issue, I found several posts advising me to clean out my browser cache, clear cookies and check to see if my wp-config.php file ends with a blank line.

None of those fixed it, so I went hunting further and saw people suggesting that one should remove any plugin code -- having a Wordpress installation with heaps of plugins, removing them one-by-one was annoying at best, but some more searching found this neat plugin to resets Wordpress back to it's installation defaults with one click.

(Obviously, if you care about the contents of your blog, or the settings you have crafted for the individual plugins, this isn't for you -- but it helped me out immensely. Kudos to Matt for inventing it.)

Nope -- didn't fix it either.

Removed my theme, restored the default Kubrick theme ...

*shazam*

Fixed.

Put my theme back, logged out, logged back in:

A White Page.

OK, at least I have something to go on, it's a problem with the theme. So I started to poke around further.

It turns out, the functions.php file cannot have spaces in between the functions you define, compare the following code:



<?php
if ( function_exists('register_sidebars') )
register_sidebars(2, array(
'before_widget' => '<li class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));

function widget_search() { ?>
<li class="widget widget_search">
<h2 class="widgettitle">Search</h2>
<input type="text" id="searchfield" />
<img id="searchspinner" src="<?php bloginfo('template_url'); ?>/images/ajax-loader.gif" alt="∗" />
<script type="text/javascript">
var search = new Search('searchfield', 'searchspinner');
</script>
</li>
<?php }
if ( function_exists('register_sidebar_widget') )
register_sidebar_widget(__('Search'), 'widget_search');

?>

<?php

function theme_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;


(code edited)



Fails, but:



<?php
if ( function_exists('register_sidebars') )
register_sidebars(2, array(
'before_widget' => '<li class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));

function widget_search() { ?>
<li class="widget widget_search">
<h2 class="widgettitle">Search</h2>
<input type="text" id="searchfield" />
<img id="searchspinner" src="<?php bloginfo('template_url'); ?>/images/ajax-loader.gif" alt="∗" />
<script type="text/javascript">
var search = new Search('searchfield', 'searchspinner');
</script>
</li>
<?php }
if ( function_exists('register_sidebar_widget') )
register_sidebar_widget(__('Search'), 'widget_search');

?>
<?php

function theme_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;


(code edited)



Works perfectly.

So where was the problem?

the blank line between the closing ?> in the register_sidebar_widget call and the opening <?php in the theme_comments function.

Undoubtably, your error will occur between a different set of functions, but if you are using a functions.php file in your theme and it begins to fail unexplainedly on you, check the file for blank lines between functions as part of your diagnostics plan.

Saturday, March 28, 2009

Microsoft's Support for XP Ending?

Interesting read via ZDNet this morning regarding Microsoft beginning the end-of-life cycle for Windows XP (and, to a similar extent Office 2003).

I find it interesting -- still having people to this day asking if I can kindly remove Vista from their new machines and replace it with XP (and to a similar extent, Office 2007 for either 2003 or OpenOffice) that MS appears to have a longer support deadline for XP than either 2000 or Vista, which have a 5 year lifecycle compared with a 6.5 year one for XP.

I wonder if it'll just cause people to a) switch to Linux or b) use a completely unsupported operating system because Windows 7 is too new and 'innovative' for them and Vista is ... well, Vista.

One thing's for sure, it will have a ripple-down effect into finally removing Internet Explorer 6 woes from web developers minds.

Friday, March 6, 2009

Removing Dreamscape's SEO 3.0 Beta from Zen-Cart

note: This article is intended for a technical audience -- you should use extreme caution when modifying a production system, as your data will be nearly impossible to recover if you use this command incorrectly -- caveat emptor.

One of the more painful things to do in Zen-Cart is removing references to broken module code from your database. You can remove all the PHP files you like, but you'll still see references in your Administration pages for the modules.

In a recent request, I had to switch multiple shops from Dreamscape's SEO 3.0.0beta1 to "something better" due to a change by several shared hosting providers to use SUPHP to protect their client accounts.

After choosing Simple SSU (which is, rather a well written module and is well supported by it's author) -- we were left with the problem of the Configuration Menu in Zen-Cart's admin having two SEO references, one to SSU, one to the older code.

For anyone in the same boat, you can use the following SQL to remove the older module's SQL code from your database:

From the Administration Panel, Go to "Tools -> Install SQL Patches" and enter the following code:


SET @configuration_group_id=0;
SELECT (@configuration_group_id:=configuration_group_id) FROM configuration_group WHERE configuration_group_title = 'Seo Urls 3.0.0-beta1' LIMIT 1;
DELETE FROM configuration WHERE configuration_group_id = @configuration_group_id AND configuration_group_id != 0;
DELETE FROM configuration_group WHERE configuration_group_id = @configuration_group_id AND configuration_group_id != 0;


note: That's four seperate lines with the ;'s ending each line.

I've also posted this as a solution to the thread on the Zen-Cart forums, you can follow the further discussion there -- if you'd like.

Tuesday, March 3, 2009

Useful 'mysqldump' one-liners.

note: This article is intended for a technical audience -- you should use extreme caution when modifying a production system, as your data will be nearly impossible to recover if you use this command incorrectly -- caveat emptor.

I always seem to use these when doing remote administration from the command line -- but when I forget if I should be using -add-drop-table or -add-drop-databases, the usual suspects from Google render terribly on my mobile phone -- so I thought i'd put them here, for later.

To backup a single database:

mysqldump -u [username] -p [database_name] --add-drop-database --lock-all-tables > backupfile.sql

To backup multiple databases:

mysqldump -u [username] -p --all-databases --add-drop-database --lock-all-tables > backupfile.sql

To restore your backup:

mysql -u [username] -p < backupfile.sql