Jump to content

Changes in SESSION data for logged in users?


Recommended Posts

  • WHMCS Staff

Hi @SwiftModders LLC,

You should ideally not use these directly. Instead, use code like the following:

<?php

use WHMCS\Authentication\CurrentUser;

$userId = null;
$clientId = null;
$ownsClientAccount = false;

// User will return the WHMCS\User\User model if the user is logged in. Otherwise, returns null.
$user = CurrentUser::user();

// Client will return the WHMCS\User\Client model if a client is selected/in use. Otherwise, returns null.
$client = CurrentUser::client();

if ($user) {
    $userId = $user->id;
}

if ($client) {
    $clientId = $client->id
}

if ($user && $client) {
    if ($user->isOwner($client)) {
        $ownsClientAccount = true;
    }
}

There should be no need to utilise the session data. Wherever possible, it's best not to interact directly with WHMCS session variables.

Link to comment
Share on other sites

16 hours ago, SwiftModders LLC said:

I am trying to find a way to have a single addon that supports both WHMCS 7 and 8. Interacting with the session data is all I have available to me.

would it not be simpler to query the config and find out the version of WHMCS installed - then if it's 7, you do x to get the value you want; and if it's 8, you do y to get the value.... and then once you have the value, you can carry on with your process.

Link to comment
Share on other sites

3 minutes ago, brian! said:

would it not be simpler to query the config and find out the version of WHMCS installed - then if it's 7, you do x to get the value you want; and if it's 8, you do y to get the value.... and then once you have the value, you can carry on with your process.

Yes, I created a WHMCS 8 detector function to adjust the way module handles specific situations. I also checked the classes doc and the User class is accessible in WHMCS 7 as well. So, I can simply just check if 8 and handle logic for users.

Edited by SwiftModders LLC
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated