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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:15:46+00:00 2026-06-10T13:15:46+00:00

I am a beginner with the htaccess use, i searched an answer on google

  • 0

I am a beginner with the htaccess use, i searched an answer on google but didn’t find something good to me.

I would like to do something easy to understand (so I’m sure there is a proper way to do it) but don’t know how to do.

I have those 3 files:

.htaccess

AuthName "Restricted Area"
AuthType Basic 
AuthUserFile /path/.htpasswd
AuthGroupFile /path/.htgroups
require group intern
require group extern
require group test

.htpasswd

user1:xxx
user2:yyy
user3:zzz

.htgroups

group1:user1 user3
group2:user2

And in php i would like to make a test on the group. I will have a lot of user in some groups and i will add and remove some so i don’t want to do :

if($_SERVER['PHP_AUTH_USER'] == 'user1' || $_SERVER['PHP_AUTH_USER'] == 'user2')

but

if($group == 'group1')

Could you help finding an easy way to get this variable $group ?

Thanks a lot,

Bastien

  • 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-10T13:15:47+00:00Added an answer on June 10, 2026 at 1:15 pm

    After some research on php.net, i found a way by matching a pattern in a file (here in .htgoups), so i did this function to get a group of a logged user.

    function getHtGroup(){
        $AuthGroupFile = file("/path/.htgroups");
        $user = $_SERVER['PHP_AUTH_USER'];
        foreach ($AuthGroupFile as $line_num => $line) {
            if(preg_match("/(.*):(.*)$user/", $line, $matches)){
                $group=$matches[1];
                break;
            }
        }
        return $group;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner java question, but I cannot understand how call-by-Value ( or Reference ) is
Beginner question: I would like to pass in window.location.hash to my form action parameter.
Beginner here: In this answer to my question of how to insert data into
Beginner here, I have a simple question. In Android what would be the best
(R beginner here...) I have a dataset like: > head(q) Date Time System User
Beginner in python, but been programming for about 5 years now. I suspect I
A beginner question I am sure, but I have just started working with a
Python beginner here. I've looked around and found similar questions but can't quite cobble
I'm still beginner in PHP. I have a small problem, I would to multiply
I'm a beginner in jQuery area and I have simple question like this :

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.