Archive for the ‘ Code ’ Category

Database Exports From phpMyAdmin Add Garbage Text After Every Link

This is an issue that has plagued me for months and months, and I finally found a way around this VERY strange bug.

For some reason, exporting a database from phpMyAdmin inserts garbage after EVERY LINK in the database content. So if you have a database row with in the data, it will end up looking something like after export. Obviously, this causes all kinds of issues.

The only way I’ve found to stop this behavior is to NOT check “Save as file” when exporting your database. Just click “Go” and let the dump print to screen. Then copy/paste it into a text file (save as .sql) and import that into your database. If the export is too large to print to screen, you’ll have to manually do a search and replace on the resulting .sql file. The hash that comes after ?phpMyAdmin= is different on every export, but luckily it’s the same in each dump file – meaning it’s relatively easy to find it and replace it.

Set media=print Using The CakePHP CSS HtmlHelper

It seemed so simple, yet it took forever to figure this one out. I’ve been using CakePHP for several projects lately, and I’m really enjoying using it. But much of the documentation is lacking. Luckily there are plenty of blogs detailing the progress of this framework and what can be done with it. But I searched in vain for quite a while on how to create a link to a css file and designate it for “print” only.

Here’s how to create a link to a stylesheet and set the media type to “print”:

$html->css(array('filename'), 'stylesheet', array('media' => 'print'));

That will output the following code:

Hope that helps the next person trying to figure this one out.

Change Your Domain Name and Keep Your Incoming Links With .htaccess And mod_rewrite

When moving our site from ablogapart.org to michaelkrol.com, this handy little bit helped move our entire website with four lines of code:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)ablogapart.org [NC]
RewriteRule ^(.*)$ http://michaelkrol.com/$1 [R=301,L]

This reference was extremely helpful.

This RewriteRule lives in the .htaccess file at ablogapart.org and tells any request coming in to that domain to swap ablogapart.org out and replace it with michaelkrol.com. This includes ANYTHING after the trailing slash, like a direct link to a previous post. So http://ablogapart.org/this/direct/link gets sent properly to http://michaelkrol.com/this/direct/link

The important part is the [R=301] which sends a 301 (Permanent) Redirect header. That tells search engines that the page has moved permanently.

Just imagine what you’d have to go through setting up individual forwarding links…

PHP mail() And Gmail – A Warning on Headers

Today, out of nowhere, we started receiving reports that HTML email the gdiapers.com site was sending were showing up as just that: HTML code and not much else. Running a few tests confirmed these reports… but only in my gmail account. We went back and checked the reports and sure enough – they were all coming from gmail users.

After some tinkering and futzing around we realized that the Windows line breaks that we had after the headers (rn) were the problem. Here’s an example:

This will show up as two line breaks in gmail and trash your HTML formatting:
$headers = "MIME-Version: 1.0rn";

This, however, will fix the problem and show up in gmail just fine:
$headers = "MIME-Version: 1.0n";

I’m sure if you were sending mail from a Windows server this may not be the case, but for those on a Unix box, just stick with n. Google will thank you by displaying your HTML email the way it was meant to be displayed – without raw code!