A
A
alex_ak12019-10-30 13:35:57
Bitrix24
alex_ak1, 2019-10-30 13:35:57

How to find out the current user from jscript in the browser in 1s Bitrix?

Hello.
To find out if a user is logged in or not from the server (and php) point of view, you can write:

<?
global $USER;
if ($USER->IsAuthorized()) echo "You are authorized!";
?>

Similarly, you can find out the username $USER->id and other names.
Is it possible to somehow enter js on the page, which will find out the same thing inside the browser, and not in the form of a finished page that came from the server and php.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
akis, 2019-10-30
@akis

is the user logged in or not from the server point of view (and php)

You correctly noted that the user can be logged into the server .
But client js can be connected to the server only through requests.
Those. if you send a request to the server, then you can reliably determine whether the user is authorized,
locally you can only collect on some indirect signs.
It is necessary to look in more detail what the task is and why it is needed.

Y
Yuri Paimurzin, 2020-01-16
@rusellsystems

for example, AJAX will check in the background on a timer, referring to a pre-prepared page
, you can specify the level of access to the page and make it a condition, for example, if js requests this page and the answer is that there is no access, you can also check the corresponding status by the timer

S
slavin3000, 2020-09-22
@slavin3000

BX.message('USER_ID');

T
Trionik, 2021-07-26
@Trionik

along the way, Bitrix has a javascript library and you can use it to do the same thing that is usually done through PEASHPE
https://dev.1c-bitrix.ru/api_help/js_lib/introduct...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question