Reputation:
How would I password protect my site? I have been throwing around ideas, so far my site is stuck with something similar to this:
<script>
function password() {
var password = prompt("Enter password:");
if (password.toString().toLowerCase() == "pass") {
location.href = "siteURL";
return true;
}
else {
alert ("Incorrect code");
return false;
}
}
</script>
However this is not hard to get around.
I was looking for something so that even by going onto the main site, they would be redirected to a password page. If they entered correctly they could return to current page, if not then they would be unable to enter. I already have the "password page" sorted. I am just wondering if there is a way to redirect to there and back. Also, would such a thing require cookies to see whether the user has already correctly imputed the password?
If anyone could direct me to useful information on this, it would be much appreciated.
I've added both PHP and Javascript in the tags as I am unsure if this is server side scripting or not.
Upvotes: 0
Views: 143
Reputation: 12369
Using PHP this can be done using the session_start() and checking if the user has authenticated via a login page. There are many many tutorials on the web.
http://www.phpeasystep.com/phptu/6.html
Upvotes: 2