SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Looking for a simple password protected page

    Hello all,

    What is the simplest way to password protect a page on a website? I have a client that wants to post a resume, but wants that page viewable by only those that have the password.

    Thanks in advance!

  2. #2
    #titanic {float:none} silver trophy
    molona's Avatar
    Join Date
    Feb 2005
    Location
    from Madrid to Heaven
    Posts
    8,271
    Mentioned
    252 Post(s)
    Tagged
    1 Thread(s)
    There are scripts already for that. Just search in google for password protection scripts in the programming language you choose. Many of them check that the password is correct by comparing it with the value store in a database. If what he wants is just minimal protection, you could create your own script:

    Code:
    $passWord="whatever";
    
    if ($POST_['passwordField']=="whatever") {
     header('location:http://www.domain.com/whateverpage.htm');
    }
    This assumes that you have a form like this
    Code:
    <form name="myPassword" method="post">
    <label for="passwordField">your password here</label><input type="password" name="passwordField" />
    </form>
    Of course, you don't need to use PHP, you can use whatever you want.

    Also, be aware that the protection this provides is minimal, almost non-existant
    Last edited by molona; Oct 18, 2008 at 07:08. Reason: correcting misspelling

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    I just uploaded my resume as a passowrd protected PDF.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This line

    if ($POST_['passwordField']="whatever") {

    Should be:

    if ($POST_['passwordField']=="whatever") {

    And this line

    header('location: ....')

    Should be

    header('location: ....');

  5. #5
    #titanic {float:none} silver trophy
    molona's Avatar
    Join Date
    Feb 2005
    Location
    from Madrid to Heaven
    Posts
    8,271
    Mentioned
    252 Post(s)
    Tagged
    1 Thread(s)
    Thank you for the correction Inexplicit. I always write in a hurry You are quite right, for comparision purposes, I should have used == and it is always good practice to place the ; at the end of the line, even if it is the very last.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •