Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 237497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:25:48+00:00 2026-05-11T20:25:48+00:00

I was going to use .htaccess to password protect a directory for a php

  • 0

I was going to use .htaccess to password protect a directory for a php script I’m writing, as I do not trust my PHP skills to create a secure login, but I found out you cannot use relative paths for AuthUserFile and I could not generalize this.

If you could direct me to a secure PHP login script to password protect a directory I would be very grateful. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:25:48+00:00Added an answer on May 11, 2026 at 8:25 pm

    One thing you can do is keep all your “secret” files in a directory outside of the server’s webroot. All access to these files can then be routed through a single PHP-script inside your directory. Something like this:

    http://www.example.com/protected-directory/access.php?file=/foo/document.doc

    With a directory structure such as this:

    +--+ /server_root
       |
       +--+ /web_root
       |  |
       |  +--+ /protected-directory
       |     +-- access.php
       |     +-- access-denied.html
       |
       +--+ /protected_root
          |
          +--+ /foo
             +-- document.doc
    

    In your access.php you would do something like this:

    $file = $_REQUEST['file'];
    if ($user->hasAccessTo($file)) {
        readfile("/server_root/protected_root/$file");
    } else {
        readfile('access-denied.html');
    }
    

    Now, you have to be careful that you make sure nobody screws with your file-parameter and passes something along like "../../../etc/passwd". Also, you probably want to make sure you send the correct headers in the above example, I omitted that for reasons of clarity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going to use Codeigniter's session data for my login system, but first I
I was going to use the program called Tiled , but decided not to
I am going to use a single LOGIN database (Sql forms authenication) to hold
I'm trying to protect a folder using '.htaccess' and '.htpasswd'. I used http://www.tools.dynamicdrive.com/password/ to
I was going to use Zend_Cache, but it says here that it's not the
im going to use Sociallib library in my app to interact with social networks.
I am going to use the jquery autocomplete plugin and i will to set
I am going to use a HSlider to set a range of values. I
I am going to use singleton classes to manage both DB connections and references
I was just going to use the FileUpload.FileBytes property but looking into the respective

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.