Base href, the simple solution

Posted: October 13th, 2014 | Author: | Filed under: HTML, Internet, PHP | No Comments »

I’ve been grappling for a while with a problem. The site I’d created, due to using mod_rewrite to create URLs that didn’t actually exist, was creating a virtual folder structure that meant that I was having to create specific sidebars and navigation elements that included the right level of linking.

This being a PHP site, I’d tried to resolve this by using variables such as $_SERVER[‘PHP_SELF’] to try and automatically resolve the server address to provide a relative file path, but this had mixed results.

Turns out that the answer was the not frequently mentioned base html tag – this is a tag that I was sort of aware of, but had forgotten. Indeed, an otherwise excellent HTML book I read the other day didn’t even mention it…

Simply adding

 <base href = "" /> 

to the site made included headers, sidebars etc instantly portable, no matter the folder depth.

Of course, this being a PHP site, I set the base URL in my site’s config file i.e.

$baseurl = "";

then called that in my site header:

 <base href = "<?php echo $baseurl ?>" /> 

so I only have to change the config file for different servers/environments.

Using mod_rewrite for a Christmas frontpage

Posted: December 15th, 2012 | Author: | Filed under: .htaccess, Internet, mod_rewrite, Programming | No Comments »

I needed to add a quick splash to our homepage to give an update on our Christmas opening hours.

I added a quick jQuery pop-up to our index.php, then saved that as index_xmas.php.

Then it’s a simple matter of adding a line to our .htaccess file:

Redirect 302 /index.php

All requests to index.php are now sent to index_xmas.php.

The “Redirect 302” code tells the browser that the redirect is temporary and that it should continue to use the regular URL.

After Christmas all I have to do is remove that line from the .htaccess to resume normal service.

Converting MYSQL DATEs for PHP

Posted: July 30th, 2012 | Author: | Filed under: Internet, MYSQL, PHP, Programming | No Comments »

A site I am working on stores the date of new entries to the database by using MYSQL’s CURDATE() function. So if we’re adding a new entry with the make, model and date to the database, the SELECT query looks like this:

"INSERT INTO table_name (make, model, date) VALUES ($make, $model, CURDATE())"

This works fine, but when I then query the database, like so:

"SELECT make, model, date FROM table_name WHERE ..."

The date returned is in MYSQL’s date format, which is YYYY-MM-DD.
I was looking around for a quick and easy way to convert this in PHP to the UK DD-MM-YYYY format, and kept coming up with longwinded ideas for converting the MYSQL date to a UNIX timestamp, and then using all kinds of guff to format this as required.
It turns out the answer’s much simpler than that, if you use MYSQL’s DATE_FORMAT function. By passing in your date column and the format in which you want it presented you can create a new variable to query. So the previous query becomes:

"SELECT make, model DATE_FORMAT(date, '%d/%m/%Y') as formatted_date FROM table_name WHERE ..."

The %d/%m/%Y part is where you define how the date should be formatted. Dan Winchester has an excellent and comprehensive list of options on his website.

Now, instead of your PHP looking like:

$make = $row['make'];
$model = $row['model'];
$date = $row['date'];

it becomes:

$make = $row['make'];
$model = $row['model'];
$date = $row['formatted_date'];

thus returning your date information nicely pre-formatted by MYSQL.

Mod_rewrite on BT Business hosting

Posted: July 23rd, 2012 | Author: | Filed under: .htaccess, BT, Internet, mod_rewrite, Programming | No Comments »

I was banging my head earlier with a mod_rewrite problem. The site in question is to be hosted on BT Business hosting. My mod_rewrite rules were running perfectly on my local MAMP environment, and on my test environment at Dreamhost. But it kept crapping out at BT.

Solution – it turns out that BT’s hosting needs the RewriteBase condition filled in. In my situation I was running the test software in a directory called ‘test’ so I needed to add

RewriteBase /test

to my .htaccess file.

When I move it out of ‘test’, to the full domain, I will modify .htaccess to

RewriteBase /

Hope that saves you a bit of head-scratching!

Indie labels withdraw from Spotify

Posted: November 18th, 2011 | Author: | Filed under: Internet, Music, Spotify | No Comments »

Looking at my subscriptions in NetNewsWire, I realised that one of the brown, “not recently updated” ones was my own. Oops.

Anyway, here’s an interesting article from –

200+ labels withdraw their music from Spotify: are its fortunes unravelling?

Dropbox and its new terms of service

Posted: July 4th, 2011 | Author: | Filed under: Internet | No Comments »

Excellent write-up by Chris Randall of Analog Industries on Dropbox’s wide-ranging new rights to the stuff you share with them.
Terms of (Dis)Service…

iTunes and the modern citizen

Posted: June 30th, 2011 | Author: | Filed under: Apple, Internet, Music | No Comments »

Excellent post by smithsocksimon on the troubles faced by people such as himself who regularly move country when it comes to iTunes purchases and accounts.

No Schengen for iTunes

Google Swiffy

Posted: June 28th, 2011 | Author: | Filed under: Internet | No Comments »

Well, what do you know? One minute I’m talking about avoiding Flash, next minute Google publish a tool to convert your Flash content into nice HTML5.

Ladies and Gentlemen, it’s Google Swiffy

Life without Flash

Posted: June 23rd, 2011 | Author: | Filed under: Internet, Mac | No Comments »

Just read an interesting post by Shadoe Huard – 7 months Flashless – about, well, not using Flash for 7 months. I’ve been doing the same for some time, and it’s transformed my browsing experience.

As an iPhone addict, I’m used to having Flash content denied to me; however I’m also used to having alternatives provided to me. iPhone content developers are increasingly using HTML5 to provide iOS-accessible content, and this is coming to the desktop too.

I’ve not gone to the extreme of completely removing Flash, but I have employed workarounds. The greatest is ClickToFlash. This excellent Safari plugin disables Flash content, replacing it with a box notifying you that there is Flash content. You can then click on the box to enable the Flash content, should you wish. The benefits are tangible – pages load faster, and the fans on the MacBook don’t whir up to 10000000 rpm!.

There are a few sites out there that are still sadly heavily Flash reliant. I’m a Liverpool fan, so I visit every day. This site unfortunately uses a great deal of Flash navigation. The good thing is that ClickToFlash offers the option automatically to enable Flash content on a site-by-site basis. This means that the site displays as it is meant to without me having manually to enable the content on every visit.

YouTube is of course another Flash-based site. ClickToFlash however blocks the Flash video and serves up the HTML5 video that they provide anyway for iOS devices. The result is much lower processor overheads for watching web video. Not just YouTube – Vimeo is also served up as HTML5.

Probably the most insidious usage of Flash however is advertising. A combination of ClickToFlash and the methods outlined in my recent post about ad-blocking mean that you can view websites in peace. A problem with Flash is that hovering the mouse over a Flash ad normally doesn’t show where the link goes to, so it can be difficult to find the server to add to my block list. Techniques have also been developed to obfuscate the link in the source code, so just blocking the Flash full stop does the trick.

Simple common sense

Posted: June 22nd, 2011 | Author: | Filed under: Internet, Mac | No Comments »

A few weeks ago there was a great hullabaloo about the first large-ish scale trojan to hit Mac OS X. MAC Defender and its variants were heralded as the first in a wave of threats against the Mac platform, and proof that we Mac users were about to be knocked from our smug high horses.

Well, let’s get this into perspective. OS X is now nearly 10 years old, and this is the first instance of a piece of malware running wild. And the thing is, it’s entirely avoidable (as are many Windows infestations) by using simple common sense.

Here’s a picture of a MAC Defender window.

MAC Defender

MAC Defender, from (click for large version)

This scary looking window relies purely on social engineering to make you accept its warnings. It looks like an official window, but is it? Look closely.

Firstly, there’s its name – MAC Defender. Macs are Macs, not MACS. Why the capitalisation? Then read the text. It is littered with grammatical errors and non-sensical sentences – “The largest worldwide companies trust MAC Defender their nets and security”, for example. Does this look like the work of an official product, or a bunch of scammers?

Then consider the ultimate purpose of the application – to harvest credit card numbers by making you buy their product (amusingly the window pictured shows the words “credit card” capitalised, as the creators of this trojan promise to protect you from exactly what they’re up to).

Simple common sense dictates that you do not ever type your credit card information into something that has appeared on screen unbidden.

You can protect yourself more though. A glaring flaw in the Mac’s security has always been Apple’s decision to allow downloads to open automatically. This is what has allowed this malware to infect people – visit an infected page, or click an infected link, and not only does the malware download but is able to open. You can protect yourself by turning this option off in Safari.


Safari preference window

Safari preferences

Make sure that the last option “Open safe files after downloading” is unchecked. Now whatever is downloaded to your machine, by choice or by not, will remain in your downloads folder until you choose to open it. If in doubt about where something came from, don’t open it. Simple common sense.