It's tough to limit access to a website by browser because there is no 100% foolproof way to do it.
Your first problem is user-agent spoofing. Browsers can identify themselves with any user-agent they want to. Browsers with extensions all seem to have one that makes doing this trivial. If someone with IE6 or IE7 changed their user-agent to be that of IE8 or Firefox they'll get into a website.
You can use JavaScript to overcome that issue by using feature detection. Basically you use JavaScript to do a simple test: you check to see if a piece of functionality that doesn't exist in IE6 or IE7 exists. If it doesn't, you know it's them. The problem with this is if they turn off JavaScript they easily bypass this.
A multi-tiered approach would be to browser sniff on the server side using their user-agent, ideally in Apache or IIS, and redirect those users to a page telling them you don't support their browser. BTW, that's more polite then simply hiding the website. I'd augment that with the JavaScript feature detection method. Between the two of them you'll catch all but the most technically savy users and the odds are they aren't using IE6 or IE7 anyway.