SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict mh8759's Avatar
    Join Date
    Jun 2000
    Location
    Slovenia, Europe
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's the best way to password protect my web pages? Should I use JavaScript, PHP or anything else? Which way is the easiest and which one is the most secure?
    Anyone has any code examples?

    Thanks
    Mare

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It all depends really.

    If you want something simple, you can simply have the passwords and usernames in an SQL database, and use something like this (it's all para-phrased of course, this code will not actually work):

    if (isset($loginsubmit)) {
    SELECT username, password FROM users WHERE username='$user'

    if ($user == "$username" && $pass == "$password") {
    echo("Correct! Good job");
    }
    else {
    echo("Nice try, punk."):
    }
    }
    else {
    ?>
    <form action="<?php echo("$PHP_SELF"); ?>"
    method="post">
    Username: <input type="text" name="user"><br>
    Password: <input type="password" name="pass"><br>
    <input type="submit" name="loginsubmit" value="Login"><br>
    </form>
    <?php
    }

    Hope that helps.


  3. #3
    SitePoint Addict mh8759's Avatar
    Join Date
    Jun 2000
    Location
    Slovenia, Europe
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks..i'll make some changes in your code and also make it to pass the values forward to another pages through query string...

    Mare

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, sounds good. Let me know if I can assist you further.

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Even easier would be to just use an .htaccess file. Let me know if you need a pointer to a good tutorial on this.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  6. #6
    SitePoint Addict mh8759's Avatar
    Join Date
    Jun 2000
    Location
    Slovenia, Europe
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what can i do with it? i think i could use it, because now i have to forward values through query string and stuff like that, so that user doesn't have to type in user/pass twice or even more times..the way i've done it now is a little complicated...
    i've made some kind of control panel for my site and i would like to have it password protected...however, i also need to protect other files in the control panel(addarticle.php,deletearticle.php etc). the easiest way would be to protect all files like TWTCommish said, but that can be very annoying for user(entering password every time).

    Mare

  7. #7
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then set cookies! Tricky at first, but simple and effective overall.


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
  •