Jump to content

users online (no current user) (php, cookie, sessions)


JesusSuarz

Recommended Posts

Hello,

I'm trying to get some way to query if a user is online.

I don't want to know the current user.

if not something you can define for example $clientid or $userid or $emailclient ...

I am making an external site. and i need to work with user sessions. (I am making a remote connection with the api).

this function does not currently exist in the api available.

I've been seeing this: https://developers.whmcs.com/advanced/authentication/

however I do not see that it allows to define the user.

I was also seeing this: https://docs.whmcs.com/Sessions

I was able to save the cookie in the database, however I can't find any way to identify the one that belongs to each user.

any idea how I can get (which users are online?) ..

(please nothing to do with smarty, only php).


postdata: forget to tell the method I use to get user authentication in my application.

create the following code for my application:

I first make a connection to the api: https://developers.whmcs.com/api/authentication/

soon ValidateLogin: https://developers.whmcs.com/api-reference/validatelogin/

soon GetClientsDetails: https://developers.whmcs.com/api-reference/getclientsdetails/

soon CreateSsoToken: https://developers.whmcs.com/api-reference/createssotoken/

// validar usuario 
$command = 'ValidateLogin';
$postData = array(
    'email' => $email_user, //post
    'password2' => $password_user, //post
);
$api_login = localAPI($command, $postData);
//var de id de usuario: $api_login["userid"];

// si se encuentra el user entonces traer detalles del usuario via email
$clientid = array(); // array que tiene el id del cliente

if ($api_login["userid"] == true) {
$command = 'GetClientsDetails';
$postData = array(
    'email' => $email_user, // email login
);

$details_client = localAPI($command, $postData);
$clientid[] = $details_client["client_id"];
}
// variable del clientid es: $clientid[0];

// crear token de session 
$command = 'CreateSsoToken';
$postData = array(
    'client_id' => $clientid[0],
);
$results_ssotoken = localAPI($command, $postData);

echo '<pre>';
var_dump($results_ssotoken);
echo '</pre>';

this will create the url with (CreateSsoToken) where the user will be redirected for autologin, however the cookie is created only after entering the client area. that's why I don't know how to get the cookie, or identify the user.

 

@brian! would you help me with this?

Edited by JesusSuarz
postdata
Link to comment
Share on other sites

Has anyone really worked with sessions in different domains with whmcs? ...

Isn't there a way to identify if a user is logged in from a sub-domain?

It seems that WHMCS should add a field in the customer table that indicates whether the user is logged in or not, it would be quite a useful function.

or if there is any other way then they should mention it.

Link to comment
Share on other sites

On 4/20/2021 at 8:06 AM, brian! said:

would using database sessions be an option for this ?

https://docs.whmcs.com/Sessions#Database_Sessions

that way you should just be remotely accessing the relevant db table - and I suspect you already know how to do that.

the problem is that this only works if you have your whmcs in a sub-folder.

however if you use another sub-domain I could not manage to transfer the cookie ...

therefore it only works if it is domain.com/whmcs

but if it is dashboard.domain.com it doesn't work.

whmcs should include a field in the database that says if the client is connected or not ... this would improve the way of querying the data through another domain with the api.

Link to comment
Share on other sites

5 hours ago, JesusSuarz said:

the problem is that this only works if you have your whmcs in a sub-folder.

I don't see why because it's in a database - but i'll leave you to it on this one.

8 hours ago, JesusSuarz said:

whmcs should include a field in the database that says if the client is connected or not ... this would improve the way of querying the data through another domain with the api.

is there a native way to detect if someone leaves the site - even the session wouldn't necessarily end immediately.

purely in terms of clients, you could query the lastlogin d&t and count how many logged in in the last X minutes - I think that's about the simplest way, but it obviously wouldn't include visitors to the site.

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.

×
×
  • 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