Password Protected web site

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
szms
Forum Contributor
Posts: 101
Joined: Thu Jun 26, 2003 12:23 pm

Password Protected web site

Post by szms »

I am planning to protect one of my web pages using Passowrd and for doing so I like to use Java Script. Could you please help me?
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Woah, you've got to be kidding me. It you're going to make a secure site, Javascript is definately not the way to go - from my view at least. It's client-sided so that's the least trustable thing - ever.

I'm sure you had a reason why you wanted it to be in client side? You should explain a little more to let us help you.

-Nay
szms
Forum Contributor
Posts: 101
Joined: Thu Jun 26, 2003 12:23 pm

Post by szms »

I am not very much worried about security. Just want to keep my site from my curious friends. That's why wanted to use client side: javascript.

If you have so,me more idea about server side, you are welcome to inform me.
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Ah, curious 'friends'. Not geeks I guess? If it was that simple maybe a simple security system would do. You can use Javascript's prompt() system.

A better simpler security system would be using cookies. That way your trusted friend won't have the annoyane of a Javascript prompt on everytime and your curious 'friends' are logged out.

Sessions, cookies, that's the way to go.

If 'they' sesiously aren't much a threat, maybe Javascript's a consideration.

-Nay
szms
Forum Contributor
Posts: 101
Joined: Thu Jun 26, 2003 12:23 pm

Post by szms »

I don't have much idea about session and cookies. Could you please let me know in detail about that.
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Here's a simple code:

you have this on all pages of the site (just include() them):

Code: Select all

<?php

if(!isSet($_COOKIE['auth'])) {
   header("Location: login.php");
   exit;
}

?>
What it does is that it checks for the cookie named "auth" in the user's computer. If it is set, then you can get to the page, if it's not, PHP redirects to the login page.

A very simple log in. Search around on google for some simple PHP Session/Cookie auth tutorials.

-Nay
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Try phpsecurepages.com
szms
Forum Contributor
Posts: 101
Joined: Thu Jun 26, 2003 12:23 pm

Post by szms »

I used the following code for entering the password but the window appears on the left top corner of IE. How can I show it in the middle of the page?

password=prompt('Please enter your password to view this page!',' ');
Post Reply