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

  • Home
  • SEARCH
  • 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

If this is my actual URL to a file: http://www.example.org/posts.php?post=example-post-name In my .htaccess file,
I'm htaccess stupid and I'm confident this is an easy one for anyone who
I'm going through a customer's server, running crazy proprietary forum software (vBulletin) and even
I have the rewrite ruls in .htaccess file under /var/www in my ubuntu10.4 server
I need to change the structure of the displayed client-side URL. I'm not too
So I have been using Minify to compress my JS and CSS which had
I have a few things in various different files that get called from different
Ive been looking all over but couldn't find anything so I am here to
A site done completely in HTML now needs to have some content added to
Bet you didn't see this coming? ;) So, a project of mine requires that

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.