Carbonized Blog

Just a bunch of stuff

Browsing Posts in Web Development

Well Apple has gone and released the memory hog that is Safari 4. It does look good but given that it uses a ridiculous amount of memory I think I will pass. It has some nice features that only work on a mac. Go figure.

Also Mozilla has released a new version of Firefox 3.5. It is marked as beta 99 but is basically something between a beta and a release candidate. it has improvements to Tracemonkey, the engine used to clean up memory usage but not sure it works that good at removing things from memory it no longer requires.

Now Google Chrome has excellent memory handling it’s just a shame it’s options are sparse, it has no extension support (even IE supports extensions/plug ins) (apparently as of version 2 it does) and the rendering engine, WebKit, is far from perfect. Sites like Facebook can prove a nightmare at times when it’s divs disappear behind it’s ad bar.

I’ve personally decided to give Firefox a break and use Flock for a few weeks.

I’m writing this because blocking by domain on my hosts pretty much kills my web site and so I have had to learn to block ip addresses. Blocking single ip addresses is simple as you just need something like the following

order allow,deny
deny from 9.120.161.206
allow from all

And that will block the computer at ip address 9.120.161.206 from being able to access your site. But what if you want to block a whole range of ip addresses such as 9.120.161.0 to 9.120.161.255? Well then we just leave off the end number like this

order allow,deny
deny from 9.120.161.
allow from all

Ok so now we get to the clever and damn fiddly bit. As of Apache 1.3 we can use CIDR codes to specify ranges of ip addresses. So another way of writing the above code would be

order allow,deny
deny from 9.120.161.0/24
allow from all

and that would do exactly the same as 9.120.161. but we can do so much more. After the break (ie click the read more link) I will show a list of the CIDR codes and what they do.
continue reading…

Whilst surfing the ether we call the internet I came across a list of top ten javascript functions by Dustin Diaz. As the saying goes it does exactly what it says on the tin. It is a collection of ten (and a bonus one) basic javascript functions that most Javascript writers will need/use quite a lot. Such functions as adding onload events to the window even if you’re not sure that it’s already been set by another script. getElementByClass which to me is something that should of been in Javascript from the start :mad: . If you write Javascript then you will find atleast one of the functions useful.

And I know it was written in 2005 but the functions are just as valid today.

I recently decided to try / review a new anti virus program I had heard about called Rising Antivirus. Now my first issue with this anti virus is the fact that the installer is over 60MB and the download was slow as hell. Took me around 30 minutes to download and I’m on a 20Mb connection. Once installed it takes over 200MB of hard drive space. First thing I did was run an update and it seemed to me that every component had an update and given I had only just downloaded the program this seems excessive. Next I ran a scan of the local drives. After twenty minutes I stopped it as it had only done about 5% and was saying it had over an hour left to go. Given this was my laptop with little on it this was far from acceptible.

Now we get to the main reason I swiftly uninstalled it. I downloaded the Eicar test file which is a standard file that all antivirus programs recognise as a test file so you can test if your antivirus is working or not. So I put the eicar.com file on my desktop and ran it. Rising Antivirus did absolutely nothing. I can accept it not detecting it during the download because my favourite free antivirus, AntiVir, only scans files when they are opened or read. To not detect the test file when run makes me wonder what else it doesn’t detect. I told it to scan the eicar.com file and it alerted me that it was a virus (well a test file which is what it should report it as) but not even a beep from Rising Antivirus when I run the file. In fact I had to turn Rising’s detection level up to high to get it to report it as a virus when I opened it. Even then I could see the command window in the background that eicar.com opens so I’m not even sure that if it had been a virus Rising Antivirus would of stopped it doing anything.

So my advice is avoid this anti virus like the plague. The best free anti virus, in my opinion, is AntiVir and the next best free one is Avast. I can no longer even recommend AVG as third place because all reports say as of version 8 AVG has become a resource hog that slows your computer down.

I’m a hobbyist web developer and nothing annoys me more than web sites that have obviously paid for someone to build their sites but whoever has built it has done a half arsed job.

My main gripe at the moment is sites that require you to have cookies enabled but have terrible code in place for if you don’t.

A good example is Game who put you in to an infinite redirect loop if you have cookies disabled. In fact you have to enable cookies on their site to see the page that tells you that you needs cookies enabled to view the site :|

Another bad one I just found, and this one is really really bad, is download.com. You don’t need cookies to view the site but if you have them disabled and click through to view a programs page your browsers memory usage goes through the roof. I tested this in Firefox 3.1 b3, IE8 and Chrome. With all three browsers I had to use task manager to close them thanks to download.com’s sloppy web code.

So please, if you are going to write a site that requires that visitors accept cookies, make sure you have good code in place to handle people like me who have cookies disabled.

OK thanks to Google’s Chrome and Apple now making Safari a serious browser for Windows the browser war is getting ridiculous. They all seem obsessed with how fast their Javascript engines run with Google now saying the V8 engine in Chrome 2 is 25% faster than in Chrome 1. Who cares? The speed of the Javascript engines is now so fast few people if any would be able to notice a difference in everyday use. The only people who are are Geeks who think the extra milliseconds make all the difference.

I’m not interested in how fast their Javascript engines run I just want a browser that is configurable and doesn’t eat up resources. I’m sticking with Firefox at present as it lets me configure cookies exactly how I want and has some sweet extensions. I am impressed with the WebKit engine as used in Chrome and Safari. To me Opera fell to the wayside with version 7. So at some point I may switch from Firefox to Safari or Chrome but can’t see it anytime soon. Safari 4 beta looks good but is all eye candy and eats memory. Chrome is to basic with very limited options and no black/white list for cookies. Safari also has neither a whitelist nor blacklist.

Ok I’ve been playing with Javascript frameworks like Jquery and Prototype. Now by default Jquery is 54KB and Prototype is 130KB (at the time of writing this). As you can see these are not small files. Now this is where gzip comes in. An easy way to describe gzip is that your server zips up the file before sending it to the web browser and the web browser then unzips it. Anyway by gzipping these two files using some PHP I have got Jquery down to 19KB and prototype down to 30KB!!!!

So we have Jquery:
Original Size: 54 KB
Gzipped Size: 19 KB
Data Savings: 64.81%

and prototype:
Original Size: 131 KB
Gzipped Size: 30 KB
Data Savings: 77.1%

All testing done using mod_zip test.

Anyway on to the code.
continue reading…

I recently decided to add the ability for guests to request a new captcha image (or refresh the captcha image) in my guestbook script for when it was to hard for visitors to read. As usual trying to find some instructions to do this proved useless so I had to figure it out myself. I thought I would explain how it’s done here for anyone else wanting to do this and believe me it’s very very simple.

Ok first thing we need to do is give a name to the image we are going to by replacing/changing so we add a name. For the guestbook script I added added name=”lazCaptcha” to the image tag.

eg:

<img src="http://domain.com/path/image.jpg" name="NAMEFORIMAGE" alt="" />

Next we need to create the link that the viewer clicks on to replace/change the image and for that I used this bit of code:

<a href="#" onclick="reloadImage('NAMEFORIMAGE'); return false;">request another image</a>

Notice how I put the name of the image into the Javascript? Thats so we can use this code multiple times on a single page.

Next we need the Javascript and it is very simple. We just create a random number to add to the image url to prevent it showing the cached image and then tell the browser to change the image. I’ll show two examples. The first is just when we want to display a random image and the second is how I display a new captcha image with the same code.

continue reading…

Ok been a while since I posted anything so thought I would post my tutorial on using the PHP mail() function. I have basically copied my tutorial word for word from the Lazarus forum.

This is a brief (or not) tutorial on using the PHP mail() function to send emails from your scripts.

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

Let’s break that down. The bool means that the PHP mail function returns either true or false depending on if it was successful or not. The rest is pretty self explanatory. string $to is where we put the email address we want to send to. string $subject is where we put the emails subject and string $message is where we put our message. The string part just means that this variable will be treated as a string when used. We will cover $additional_headers a bit later and won’t even touch on $additional_parameters.

Ok so we want to send an email to Bill Gates with the subject Windows Linux and our message is When is it coming out?. The function we would use looks like this

<?php
mail(‘bill.gates@microsoft.com’, ‘Windows Linux’, ‘When is it coming out?’);
?>

continue reading…

Powered by WordPress Web Design by SRS Solutions © 2010 Carbonized Blog Design by SRS Solutions