Results 1 to 3 of 3

Thread: Password Protection.

  1. #1
    Join Date
    Jun 2006
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Password Protection.

    Hello,
    How do you password protect a PHP page?
    Thanks in advance,
    Joe
    Cheap Webhosting At ONE TIME fees! Also offering Scripts, Software, Web Designs, and Graphic Designs. Outstanding Designs and Webhosting!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Here's the EASY way, but there are more complex ways.

    A "get" variable is one in the address bar... like index.php?var=value, where var is the name of the variable and value is the value of that variable.
    (note that it can be var1=value&var2=value2&.... as well)

    Once you've got that done, it's just a matter of adding this to the top of a page, assuming index.php?password=secret:
    <?php
    if ($_GET['password'] != "secret") die('No input file selected.');
    ?>

    that's really it. The die function outputs a string, in this case the same exact error you would get if the page didn't exist.... but in this case, it's a VERY nice trick because someone trying to find your secret page wouldn't even know it exists unless they knew the password and where to look... otherwise it would appear to not exist because of the "No input file selected." thing.


    Now... get values can also come from forms (just set the form's method="get" and the name of each field will be the variable name, the value the value of that variable)
    You can use POST variables... much like get, but behind the scenes, and more secure, probably better for passwords... (method="post" & $_POST['var'])

    And you can use cookies, and sessions, and likely even databases.

    It all depends... it's a very broad question, but this should explain the basics.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jun 2006
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Wha??? djr33 go on aol
    Cheap Webhosting At ONE TIME fees! Also offering Scripts, Software, Web Designs, and Graphic Designs. Outstanding Designs and Webhosting!

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
  •