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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:45:28+00:00 2026-06-09T20:45:28+00:00

the last days I was wondering how is it done? How can you authenticate/authorize

  • 0

the last days I was wondering how is it done? How can you authenticate/authorize that the user is allowed to request the data via AJAX.

For now I am using SESSIONS for auth.But this is only a minor protection.

Let´s say I have some function called addUserToGroup($user_id,$group_id), which is called via

EXAMPLE: www.mysite.com/addUserToGroup/1/2  ( user_id = 1 , group_id = 2 )

How can I check if this user is really allowed to join group_id=2? Everyone could just POST data to my server…

One solution I found is using jcryption (public/private key method). But I think,there must be an easier way to somehow check if user_id = 1 is allowed to join group_id = 2.

Thanks in advance!

  • 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-09T20:45:29+00:00Added an answer on June 9, 2026 at 8:45 pm

    I believe your question is about authorization, not authentication. If I’m right, then presumably you already know who the user is (authentication, perhaps using a cookie or something).

    Now, you have to come up with a way of determining what they are allowed to do (authorization).

    Authorization logic is really a key design decision. As such, it’s non-trivial and depends heavily on the shape of your data model and architecture of your application.

    If you can consistently determine whether this should be allowed by applying rules to the data, such as in Quentin’s response above (where living in Region 2 is enough to make it such that the User may join Group 2), then it’s usually simplest to put this logic in your entity model. In that case, I’d either create a method on User to check whether they can join the group…

    function canJoinGroup($group) {
        //if(all is well), then:
        return true
    } 
    

    Or create a method to join them which throws an error if disallowed:

    function joinGroup($group) {
        //if(all is well), then:
        return true;
        //otherwise:
        throw new Exception("User ". $this->id ." cannot join group " . $group->id);
    } 
    

    You could also add a function to Group which delegates to this new User function:

    function addUser($user) {
        $user->joinGroup($this);
    }
    

    OTOH, If the decisions about who can do what are based on more granular permissions, or based on information an administrator or user needs to be able to change at runtime, then you will have to get a lot fancier. A commonly-used, versatile, and flexible approach is called Role-Based Access Control (aka RBAC).

    This can get extremely sophisticated, but the core concept, applied to your case, is that you have a User, and Entity (the Group) and an Operation (join). You need to determine whether User 1 is allowed to do the Operation called ‘join’ with Group 2 as an argument.

    In order to do this, you will have to keep a set of rules somewhere, and then do two things:

    1. keep these tables up-to-date when new Users and Groups are added to the system, or when an Administrator changes their permissions
    2. check these tables with each request to see if the User can perform the Operation on the Entity (check whether the User can Join the Group)

    I won’t get into the low-level details of this use case. Suffice it to say that, if what you’re trying to accomplish today will eventually need to grow into a fairly sophisticated permissions system, you’d do well to study up on RBAC.

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

Sidebar

Related Questions

How can I get first and last days of the current week? What I
In the last two days, ive run across code that has php echo'd variables
I have asked a couple of questions over the last couple of days, that
One point is wondering in my mind since last few days. I want to
In the last days the bingbot is trying to access pages that don't exist
I am using Eclipse Helios. Last days I am facing problem that Eclipse Helios
I was wondering how I can go about creating an arrary of the last
I've been playing with Sublime Text 2 the last few days and was wondering
I'm been wrestling with this issue for the last few days. Wondering if anyone
In last days I was playing with C++, ASM and inline ASM. I know

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.