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 9246001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:23:30+00:00 2026-06-18T09:23:30+00:00

I am using PHP to implement HTTP Basic Authentication on the Apache HTTP Server

  • 0

I am using PHP to implement HTTP Basic Authentication on the Apache HTTP Server (version 2.2). The only directory I want to password-protect is a sub-directory of the main public web root of my website (for example purposes, let’s call the protected directory ‘/private’, and its realm “Private”).

If possible, I want users that have already been authenticated in the “Private” realm – and those users only – to see customised content on the web site’s home page (and any other web page, for that matter).

What I want to know is, is it possible to do this without forcing a login prompt at the top-level of my domain’s top-level (e.g. www.jdclark.org or, for that matter, any other URIs outside if the “Private” realm)?

EDIT:

One technique that I have thought about applying to achieve the above is as follows: When a user has been authenticated into the “Private” realm via the access control in the ’/private’ directory, a session cookie could be set in PHP.
I could then check for the presence of this cookie (which could possibility contain a session ID or some kind of unique random string), but although I’m don’t proclaim to be an IT security expert, this method feels a bit “hackish,” and something tells me that this is insecure (e.g. would it be trivial for a malicious user to spoof that cookie with an HTTP header?).
Any advice would be very much appreciated.

  • 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-06-18T09:23:31+00:00Added an answer on June 18, 2026 at 9:23 am

    Check for the presence of the HTTP authentication headers and use this to determine what to display.

    if (isset($_SERVER['PHP_AUTH_USER'])) {
        $username = $_SERVER['PHP_AUTH_USER'];
        $password = $_SERVER['PHP_AUTH_PW'];
        // validate login credentials
        $private = true; // or false if validation fails
    }
    
    if ($private) {
        // load special view
    }
    else {
       // load normal view
    }
    

    This will not prompt the user to log in if they have not already done so elsewhere.

    If you are going to be doing this in multiple places it would make sense to have a single re-usable class or file that provided a function to check for the headers and validate the credentials (returning true on success, false on fail) rather than duplicating code.

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

Sidebar

Related Questions

I am using less php and want to implement an uncompiled version of the
I'd like to implement a multiselect function using jqGridRender (the php only version of
I'm trying to implement SpringMVC + Quercus as described at http://blog.caucho.com/2009/04/14/using-php-as-a-spring-mvc-view-via-quercus/ . So I
I want to authenticate to another site using HTTP Digest authorization in PHP script.
Im trying to learn php by doing a little project using apache server. I
I'm looking to implement a REST client in PHP, and have previously been using
Using PHP I'm trying to download/save the following image: http://www.bobshop.nl/catalog/product_image.php?size=detail&id=42428 When you load this
I am using zend framework on windows. I want to implement ajax in my
I'm using the following code to create an xls file from php. http://www.appservnetwork.com/modules.php?name=News&file=article&sid=8 However,
I am trying to implement a threaded comment system using php, and i found

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.