Prompting for a password only once per session

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Darvon
    New Member
    • Sep 2007
    • 1

    Prompting for a password only once per session

    Hello everyone. I have this website I would like to add some simple password protection to.. Nothing too fancy, so I decided to pull out an old javascript I came across sometime in the past that would work just fine. Only problem was, my main website works on a php webpage that refreshes as you go through folders and files.

    So everytime I clicked a folder to go in and view its contents, the password script would reapper again, asking me to place the password in once more.

    Could someone help me modify this code in order to only have it popup once per visit? I have this java popunder script for my music that uses this cookie sort of method so it doesn't keep popping up after each refresh.

    Here's the basic code:
    Code:
    <SCRIPT language="JavaScript">
    <!--hide
    
    var password;
    
    var pass1="yourpasshere";
    
    password=prompt('Only those who have been granted the password may enter this page..',' ');
    
    if (password==pass1)
      alert('Password Correct! Click OK to proceed!');
    else
       {
        window.location="sorry!";
        }
    
    //-->
    </SCRIPT>
    Would really appreciate it if someone could help me with this.

    -Thanks!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Darvon, welcome to TSDN!

    I would suggest that you password protect your pages using server-side code. It's easy to view the source and see the correct password.

    You can also use sessions in PHP to remember users.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

      Comment

      Working...