You are currently browsing all posts tagged with 'code tidbits' in the JHuskisson.com post archives.
-
Force www. in your URL using .htaccess
Insert this into the top of your .htaccess file, making sure that ‘RewriteEngine On’ comes before it:
RewriteCond %{HTTP_HOST} !^www\.jhuskisson\.com [NC]
RewriteRule ^(.*)$ http://www.jhuskisson.com/$1 [R=301,L]Replace jhuskisson.com with your chosen domain and make sure if you are placing any full stops within the first line to enter a backslash before each full stop. This will prevent the code from not working.
6 Comments » -
‘Send me a message on AIM’ link
It’s very simple:
<a href=”aim:goim?screename=username&message=hello”>Send me a message on AIM</a>
Simply replace username with your required AIM username and replace ‘hello’ with whatever message you wish to set for the user to send you. You can remove ‘hello’ altogether if you don’t wish to pre-set a message for a user to send you upon clicking the link.
1 Comment » -
Re-enabling error reporting in MAMP
For some reason error reporting is turned off by default in MAMP.. So this is how to re-enable it to how it should be.
1. Find your ‘MAMP’ directory in ‘Applications’
2. Find ‘conf’ and open it up..
3. Open up php4 or php5 (depending on your enabled version)
4. Line 270 should be something like this:
error_reporting = E_ALL5. Line 277 will be:
display_errors = OffChange this to:
display_errors = On6. Restart servers
And voila! We have PHP errors..
14 Comments » -
Track outbound links for Google Analytics automatically
Place this code before the </body> tag and it’ll track all outbound links that aren’t part of your website.
<script type=”text/javascript”>
if (document.getElementsByTagName) {
var ahrefs = document.getElementsByTagName(’a');
for (var i=0; i<ahrefs.length;i++) {
if (ahrefs[i].href.indexOf(’http://www.jhuskisson.com‘) == -1 && !ahrefs[i].onclick) {
ahrefs[i].onclick = function () { var track = this.href + ”; urchinTracker (’/outgoing/’+track.substring(7)); }
}
}
}
</script>Simply replace http://www.jhuskisson.com with your own site URL and hey presto - all outbound links that aren’t internal are being tracked by Google Analytics.
13 Comments » -
From PHP 4 to PHP 5.. PHP Fatal zlib error: imagepng()
Getting this error?
PHP Fatal error: imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib error in example.php on line 10
Fix it easily by changing your compression variable of imagepng, imagegif or imagejpg/imagejpeg into a 1-10 ranged number - instead of the PHP 4 1-100 standard.
It should work smoothly now :)
4 Comments » -
Never lose visitors from old URLs again
Was coding a script for redirection of old URL’s into new ones for Wordpress when I found this plugin.
This plugin redirects the old ?p=1 ?page_id=1 URL structure as well as handling feedburner re-direction. Which saved me a lot of time and frustration. It also means converting sites not using permalinks into sites with permalink structures is a simple case of enabling this plugin. I love it!
No Comments » -
Easily insert a Xbox Live gamer card into your website
Searched for about 30 minutes on how to do it earlier today as mygamercard.net is extremely slow and unreliable. Here’s how to do it yourself by using Xbox.com (which is very reliable and fast):
<iframe src=”http://gamercard.xbox.com/MyGamerTag.card” class=”gamercard” width=”204″ height=”141″ scrolling=”no” frameBorder=”0″></iframe>
Simply replace MyGamerTag with your own - and insert it where you would like your gamer card on your site - simple.
2 Comments »


