Archive for the ‘Tech’ Category

Accessing MySQL with ASP

Tuesday, December 30th, 2003 | Programming, Tech

Being an active server page coder by nature, all my sites are in ASP. So eventually I hit a problem – two sites want to use the same Access database but they are on different hosts. Therefore I decided it would be best to use a MySQL database that they could share by making remote connections.

Why use MySQL?

The main advantage is as I have already mentioned, having a central MySQL database allows you to connect all your sites directly to it and access the information. There are ways to do this in Microsoft Access but they are patchy at best. The other option would be to use MS SQL server although this doesn’t come cheap from any host.

Changing the code

Let’s say for example I have a MySQL database on a linux hosting account at www.examplelinux.com. And I have a website at www.examplewindows.com that I want to connect with. Luckily connecting to MySQL is similar to any other connection except we just need to make a few changes.

The first is obvious; the connection script needs to be changed as we are accessing MySQL rather than an Access database. The second are certain changes in the scripts to make sure we don’t end up with any MySQL errors.

A typical DNS less connection would be something like:

Driver={Microsoft Access Driver (*.mdb)}; DBQ=" + Server.MapPath("/Conndb/springer1.mdb")

Whereas a connection to MySQL would look more like:

Driver={MySQL ODBC 3.51 Driver}; Server=examplelinux.com; Database=dbname; UID=username; PASS=password

To do this your server needs to have the MySQL driver on it. You can download it from http://www.mysql.com/downloads/index.html. You can also use a DNS connection if you have one which makes things considerably simpler:

DSN=linuxexampledns

All you need to do is replace the connection line you currently use with the new one modifying the username, password and name of the database you are going to use on your target server.

Further modifications

To make the ASP code work with MySQL there are a few other modifications you need to make with your code. The problem arises from the use of the ‘ character. Where Access is ok with it, MySQL will bring up a nice big error message.

Luckily a bit of PHP style code can come to the rescue. If you are familiar with PHP, you will know you can remove the significance of a character using \ before it. Therefore a quick replace function does the trick

Replace(string, "'", "\'")

So for instance a select command would go from:

SELECT * FROM hobbies WHERE firstname = '" + (users.Fields.Item("firstname").Value) + "' ORDER BY name ASC

And changed to:

SELECT * FROM hobbies WHERE firstname = '" + Replace((users.Fields.Item("firstname").Value) ,"'","\'") + "' ORDER BY name ASC

Setting up the server

Once the modifications to the code have been made you can get on with setting up the server to accept the requests. First of all you need to allow the scripts to access the database.

In CPanel goto MySQL Database and scroll down to access hosts: then add in the IP address of www.windowsexample.com. If you can’t find it out, simply run the scripts and it will bring you up an access denied message containing the IP address you are trying to access the database from.

In Direct Admin goto MySQL Databases, click on the database and then you can enter the IP address in to the access hosts form near the bottom. If you can access the privileges section in phpMyAdmin directly you can also do it from there as you can set for each user what access host the user can use.

The only other problem is getting the contents of your Access database to your MySQL server. The easiest way I found to do this way to set up a DNS connection to the MySQL server on my local machine, though you may be able to do this directly to the server providing you grant yourself access, and then going into Access and Exporting it.

File > Export then open the drop down menu at the bottom and and scroll to the bottom of the list until you see ODBC Databases (). This will close the export window and prompt you to enter the name of what you want to call it when you export it. Most likely it will be best to leave the default here.

Then it will come up with a box asking you to select a data source. Select the machine data source tab and find your DNS connection on the list then click ok and your done.

Conclusion

Switching your database from Access to MySQL is a hassle – you need a Linux server, code changes and connection scripts. However if your sites need to share a database its a far cheaper option that using MS SQL.

Printer friendly pages

Saturday, October 18th, 2003 | Programming, Tech

There is nothing like reading an article on the website and finding it one of the best you have ever read – you immediately want to show to it other people. You flick the switch on your printer to on, hit Control + P and prepare for it to emerge. But what do you get? A mess of DHTML, adverts or half the text missed off the edge of the page.

You could always hope the visitor turns their page to landscape but with the length web pages usually turn out like it is not very likely. Save them the trouble of having to print selection or copy and paste into a word processing package by making your pages printer friendly for them to print straight from.

Making them friendly in the first place
There are two main ways to allow visitors to print the pages easily. The first is to make the original web page with the article or content on, the right size to be able to print. For liquid width sites this is ok as long as they can condense down although for fixed width sites this is not as easy.

Generally you have a width of about 600 pixels, which the users printer will print. This is good if you have a navigation or sky scraper advert down the site taking the last 200 pixels of your page as the user does not need these printing. Although if your article goes all the way to the edge its time to rethink the design.

One way of getting round this would be to have a link, which chances the width of the page. The user clicks a link to say somepage.php?mode=printer. Then you could have something, which says if the mode is set to printer the page width is altered to 600 rather than 800 pixels using server side scripting. This could also be done to a certain extent using JavaScript so the page will not always have to be reloaded although in some browsers it may have to be and there is more chance of it going wrong.

The printer friendly page

This is a more common solution to the problem of visitors not being able to print. All you have to do is set up a separate page without all your adverts, logos and navigation, which is less wide or uses a liquid width so that the user can print this.

Generally you wont want to include adverts on this page, otherwise visitors may not use it at all as they can remove the ads themselves using print selection or copy and pasting the text. However you may want to include your logo and visitors won’t mind and it increases branding when the article is passed around.

If your articles are static then you may end up creating a separate page for each of these but if your articles are dynamic, most likely stored in a database you will simply be able to make a dynamic page just like your main article page for the printer friendly page and link them together.

Making it usable

Whatever solution you use you may want to include a print link to. This will encourage users to print the article simply by clicking the link, as their finger will already be on the mouse button, so users who would not normally print the article may give it a click.

Another good point about users printing the whole page rather than copy and pasting the text into a word processor is that the URL of the page will be at the bottom so other people who read it will see it and when the visitor looks at it later they will remember your website.

Intellectual property and protest sites

Sunday, October 12th, 2003 | Life, Tech

A lot of people are using the internet to speak out against the companies that they object to. From the global protest sites such as www.stopesso.com to the small one man operations, protest sites are springing up all over the net. But can it be done without attracting a ball of law suites?

Starting these websites can be a problem on two fronts. The first problem is that if you start printing lies about the company they wouldn’t be happy about you bad mouthing them. The second is that if you register a domain such as www.xyzsucks.com are you breaking the trademark of xyz?

The first problem is easily to solve – don’t say anything unless you can prove it. First of all making up lies isn’t going to help the site as it will discredit it if it is discovered to be a lie and secondly it’s not really fair on the company. Which is why the can sue you if you start publishing lies. Stick to the truth of why you don’t like them though and they pretty much cannot touch you.

As for the second problem there is always the solution of not using the companies name in the website name but then how will people know the site is about that company? The good news is this is not a criminal act so even if the company does get angry, police are unlikely to come round knocking on your doors.

As huumor pointed out on one of my favourite web developer forums:

“if you hate McDonald’s and make a “hate” site called www.McDonaldsSucks.com – you are probably more likely going to be #”¤#&”¤-ed by McDonalds lawyers than if you would use www.CrapDonalds.com – with this domain name you’re not using the copyrighted McDonald’s in it…”

The problem is going to come from ICANN’s decisionon whether you can keep the domain or not. Some sites including www.walmartcanadasucks.com have been allowed to keep the names whereas a recent Reg Vardy protest site had its domain handed over to the company.

There is no clear rule on this one although running a search on The Register throws up some interesting results.

Does my business need .biz?

Friday, August 1st, 2003 | Programming, Tech

Until now companies had it pretty easy. You choose a .com domain although if you were a British company you may have had to choose between a .co.uk as well. Times like that are gone now however. Now businesses have to pick between extensions including .biz for all companies and .us for US companies.

The problem is that nobody wants an unpopular extension and if dot biz does not take off many businesses could be stranded with a useless domain. Although dot biz are gradually becoming more popular and its not lucking like one that will fade out any time soon; although the best option is often to play it safe.

Dot biz problems

Domain extensions have been launched many times with the hope of climbing to the success of the dot com. But none of them have done and my guess is that none of them will do any time soon. To be popular you had to be quick off the mark.

Dot net and not org were popular as they are very widespread and .co.uk has done very well too as it was out well before it was all the crazy to bring out your own domain extensions for your country. Back when nobody hard heard of dot tv, dot ca and dot us, .co.uk were selling like hot cakes; making them very cheap helped too.

The problem is though that dot biz was not quick off the mark. And many of the big websites had already set up sites when the dot biz sales doors where opened for business. Many large corporations who could have promoted dot biz already had dot com’s by then and were not about to change.

The dot com seems like the perfect extension too. It is spelt like it sounds, its not too short and its not too long. The problem with dot biz is that unless it becomes very popular people could easily confuse the spelling with bis. And no business wants some of its website traffic heading off to an address which does not exist.

Those names though

As will any new extension however people will be tempted by the fact they can get find a name shorter than a paragraph in length which hasn’t been snapped up already. While people are cueing up on services like SnapBack to get stupidly long dot com domains, it’s easy to find a great name that ends in dot biz.

There is no localisation on dot biz as with many other domains neither. For instance owning a dot us is great and your website visitors will love it – providing they all come from the US. But chances are they won’t be, and people who don’t live in the area your name is from could feel like an outsider. This is not a problem with names like dot tk as everyone feels like an outsider together ;). I mean how did an island that small get an internet connection let alone a domain name extension in the first place?

Conclusion

If your company name is available in a dot com then go for a dot com. Dot com is still and for a while yet will be the dominant name. However if you can’t get it then a dot biz looks professional and chances are you can get your name. If so I recommend that you go for it. After all the dot biz popularity grows every time a registration is made.

Avoid using initials in your domain names

Friday, August 1st, 2003 | Programming, Tech

Just look around expired domain lists and domain auction sites and you will probably find an advert for “rare 3 letter domains.” However, there is a reason these are rare – nobody wants them! Who wants a domain such as www.h5l.com? It’s pointless. It takes longer to say that than www.freeservebusiness.com. Yet the second domain has 6 times more letters in.

Initials are not something that you want to go for. The ideal domain is likely to be one word. Two words is also ok as long as there is no dash between them. When choosing domains you are looking out for how few syllables you can have rather than how few letters you can have.

This is where initials drag your time up. Although they only have a few letters, each letter is a syllable so it takes a while to say them. A lot of popular website domains use one word with two syllables, such as www.google.com, www.mworld.us and www.yahoo.com.

Picking a memorable domain name

Tuesday, February 18th, 2003 | Programming, Tech

When choosing a domain name or any web address for your website it is important that you get a memorable and snappy domain so people can remember it. There are also some things which you should not do.

Make it flow

One thing I think should never be included in domains is an “-“. They should not be put in. Take a look at these two examples:

www.bigcats.com
www.big-cats.com

Try saying them. The first one is simply “bigcats .com.” Whereas the second one is “big dash cats .com.” Much more complex and so much harder to remember. Domains are far more snappy if the words follow on without being broken up with dots and dashes. Why do you thing nobody has bought a .name domain?

Words not letters

Many people are going on about how they are selling rare 3 letter domains. The problem is that these domains are usually a mix of random numbers and letters. It’s much easier to remember a name than some random initials. Don’t just get the initials of your domain when its more complex. Get the full name.

Simple words

Not everyone is a great speller. Try to keep the words in your domain simple and try not to use words which are often spelt wrong. If you really must do this then you should buy up alternative spellings to your domain and set them to redirect to the correct domain name.

New TLDs – positive or negative?

Monday, February 17th, 2003 | Programming, Tech

Back in the old days you could pick between all 3 domain extensions, .com, .net and .org. And each one would cost you £100 a year or over. Now you can pick between 100’s of domain extensions from .cc to .sk. And you can register domains from as little as £3 per year.

This causes problems though. Back in the 90s if you were looking for a website you hardy had to guess at the web site address because they were all .com’s. Now-a-days there are so many you may never find the correct site.

For instance, Worfolk Online uses 5 different domain extensions including .biz, .tk and .us. Guessing the address of M World if you didn’t know the address could take a while. How many extensions would you go through before guessing .us?

The trick is getting the compromise right. New extensions allow you to get a better domain name but you have a not so good extension. Whereas if you go for the classic .com, most of the good domains are taken but when you are looking for a website .com is and I’m guessing always will be the first extension people go to.

Is your expired domain worthless?

Saturday, February 15th, 2003 | Programming, Tech

Buying expired domains can get you valuable visitors and an already strong standing in search engines and website directories. However if you pick the wrong domain you can lose traffic, popularity and reputation.

Search Engine Bans

Everyone hates those sites that occupy domains and have sites with one a homepage covered in Spam and paid for search listings links. And so search engines have various methods to counter the Spam pages with spoil results and annoy searchers.

One system that many search engines use, including Google, is to permanently ban Spam addresses. The ban can be appealed but this takes time and effort, which you really don’t want to be wasting. The key is to find out before you buy.

Research the owner

Does the previous owner, own one domain or one hundred domains? If they own loads of domains, the chances are that they will all be part of an interconnected Spam network set up to fool search engine spiders and generally annoy people.

Research the site

Check out the Way Back Internet Achieves (http://webdev.achieves.com) who spiders many sites and keeps records of how the website used to look since 1996.

Conclusion

Before registering an expired domain, make sure that you have researched it first. If you do you are likely to end up with a great domain bringing your visitors and search engine listings.

Picking a width for your website

Wednesday, January 29th, 2003 | Programming, Tech

So you’ve designed your perfect homepage. The only problem is that it doesn’t fit on anyone’s screen but yours. Suddenly you are finding you have to redesign your site so it is more accessable to everyone and your amazing designs and idea’s are laid to waste.

When first building your website you need to decide how wide your going to make it. If its just formatted text going across the screen then you are ok, but for most of us, we need to set a width for our tables and layers which is bound to cause problems somewhere along the line.

100% width

The easier way to make a site fit is to set the width to 100%. It will stretch across any screen so no problems you say. However its not as simple. Designing a site with 100% width is not always that easy as you have to make sure everything will squash down – no point using 100% width if your images won’t let it go down futher than 900 pixels.

You still really need to pick a width as any images and menu’s that make your site wide will set the width for you. People on 640 X 480 screens with browsers in shrunk mode would probably like your site to squash down to about 400 pixels. Test if your site will do that (though don’t worry if it won’t).

100% width works good for sites such as Microsoft.com and Worfolk.biz who have a lot of product information and so use text with can go across the screen and still squash down easily.

700 pixels width

This is the site I use for most of my sites. I use it because I can fit a banner into it and still have room for a 200 pixels wide logo next to it. The only problem with doing this is that its slightly too big for people with 640 X 480 screens and slightly too small for 800 X 600 screens. I consider it a nice balance though.

A lot of sites go for a 800 pixels wide screen so that it wil fit on a 800 X 600 screen now as people using 640 X 480 are become rarer quickly – I’ve been using 1024 X 780 for years now. Ever Yahoo is now to big to fix on a 640 X 480 and has been for a while too.

A fixed width site works well for sites which have content in the right place, all neat and correctly laid out in sections such as Msn.com or Mworld.us.

Other options

MSN use javascript to show hide layers. If you read Java Junky (MXL Magazine column) then you will know what this is about. Bascially if the browsers screen is big enough, they add extra information dowen the left column – Full screen your browser on one of the channels and then shrink it to a fairly small size. Some content should disappear (probably the channels menu) from the right hand side.

They also have a script on their homepage so that it rearrages the content for people with 640 X 480 screens so it fits on them while using up the space nicely on a 800 X 640 screen.

Conclusion

If you site isn’t almost all text then go for a set width such as 700 or 800. If you don’t have any menu bars or extra content down the side then you might even want to go for 600 pixels like Worfolk Online uses (or used to use depending on whether it has changed since I wrote this). Test it out on different screen sizes and see what looks good. Check out what the competition does. When you’ve found something you like – stick with it.

A very, very short introduction to JavaScript

Monday, December 30th, 2002 | Programming, Tech

JavaScript allows you to adding programming functions to your web pages. Browsers will read the HTML and interpret the JavaScript. JavaScript can also produce dynamic effects using variables. JavaScript can also react to events, write HTML code and validate data.

The key parts of JavaScript are functions and events. Functions are mini scripts that can be executed by an event such as a timer or a user clicking on a link. Take a look at this basic script that brings up a gray dialog box saying ‘Yay! javaScript Rules!’

<script language="JavaScript">
<!--

function yay() {
alert('Yay! JavaScript rules!');
}

// -->
</script>

The java is in a standard script tag (which you will read about next) and also has comment tags around it. This hides the script from old browsers who don’t understand JavaScript.