How to allow only certain browsers to view the website

Hello sir/madam,
I would like to make my website only accessible through internet explorer just to mess with my teacher a little bit. I couldn’t find anything thing on the interwebs, maybe I searched wrong. Could you lend a hand.

You can add serverside code, that checks UserAgent header and acts accordingly.

4 Likes

As teresko said server side code. You get the user agent on request and then serve the page based on that logic.
What is your backend going to be and how much time do you want to sink into this.

Can you provide a bassline of code?

No, I can’t. Because you have NOT told us which backend language you are using.

2 Likes

Alright, oh yes. Html5, css and Js is that enough? Im hosting on apache

HTML and CSS are not banckend languages. And (based on your description) you are not using EcmaScript as a backend language either.

So, no, it is not enough.

The common languages for writing the backend code of a website are: java, php, c#, python and ruby. There are also ways to use javascript in that capacity, but it usually requires used of a specific framework, like Node.JS … and since you did not mention any of this, I don’t think you will be able to block anything.

Don’t waste everyones time and just do what your teacher told you to do.

3 Likes

Teresko,
excuse me. We are just making a website and he needs to check them so I could play a funny joke on him, alright. He will understand.

Well I’m not using any other languages than the ones I said so no.

Changed your thread title coz it said something entirely different than what you’re asking for.

Also as a note, people won’t be willing to just code you a solution for your problem, especially when you’re vague and don’t even want to try to do it yourself.

5 Likes

I’m not a big fan of Node, but here you go: https://www.npmjs.com/package/useragent I would much rather use PHP for this. I found this: https://github.com/jenssegers/agent/blob/master/README.md All of this begs the question of why? You can likely solve this with a better framing of the question you are trying to code the answer for.

1 Like

there was a time when you couldn’t access msn.com, which I use, from any other browser but IE, so there must be an easy solution.

Dot, this is almost perfect as we work with nodejs.

Node is super powerful, but some packages pull in so many dependencies that it can make auditing a real hell hole.

Also found this https://github.com/lancedikson/bowser

1 Like

Within your technology stack you already have at least two possibilities.
On both on them I’m not expert - I usually I try to avoid them. But I can point you in direction.

Browser side: JS

  • With JS you should be able to check the browser (the detection logic might be not straight forward).
  • This way you could clear or replace the whole page content, or simply redirect to new location.
    It will make original content being shown during the loading (assuming that we will go for simple solution) but it will work as a joke.
  • I think it connects with @dot404 suggestion of a project.
  • Your solution if server side independent.

Server side: Apache HTTP server

  • There should be a possibility to conditionally serve the content via more sophisticated configuration for apache. Either by security module, or simple https://httpd.apache.org/docs/current/mod/mod_rewrite.html
  • You will need to actually study the documentation for that. And apache configuration is very specific (not a general purpose language).
  • As a one of possibility I would suggest simply serve some folder as you do now, and with condition for agent just server specific HTML page with a joke message.
  • it will make the Apache server as part of your solution. There are many HTTP servers, but apache configuration works only with apache.
  • Obviously this will not work if you open HTML page from local disk.

Just make sure that the teacher can run other browser (so he will not fail you).

1 Like

I’ll be damned, didn’t know it was possible with vanilla js: https://stackoverflow.com/questions/5916900/how-can-you-detect-the-version-of-a-browser

I asked my teacher, he has no idea, he told me that it should work with vanilla js.

Sorry if I’m at all later for this, but you’d be surprised what you can actually do with native JavaScript these days, from multi threading to file manipulation(requires permission however)…

But all in all, that seems like a reasonably decent solution, I’ve seen more in depth one’s, but considering it’s mere browser detection, the source code seems bloated to kingdom come.

1 Like

Copy pasta from Stack Overflow. :no_mouth::grinning::smiling_imp::metal:

1 Like

Basically the job of most developers, lol! I kid, I kid… I wish it were that easy! :smiley:

1 Like