S
S
Satir012015-06-25 09:09:02
1C-Bitrix
Satir01, 2015-06-25 09:09:02

Why is IsAuthorized not working?

Can you please tell me why IsAuthorized does not work in the infoblock, but everything is ok outside the infoblock?
I created an infoblock to allow only authorized users to download the file and posted the following code:

<?foreach($arResult["ITEMS"] as $arItem):?>
<div> 
   <?if(CUser::IsAuthorized()):?> 
    <ul>
      <li><a href="<?=$arItem["PROPERTIES"]["ATT_FILE"]["VALUE"]?>">Скачать в PDF</a></li>
     
      <li><a href="<?=$arItem["PROPERTIES"]["ATT_COMMENT"]["VALUE"]?>">Комментировать</a></li>
     </ul>
   <?else:?> 
    <ul> 
      <li>
       <a>
        <span>Скачать в PDF</span>
        <span>Скачивание и Комментирование возможно только после регистрации.</span>
      </a>
      <li>
       <a>
        <span>Комментирование</span>
        <span>Скачивание и Комментирование возможно только после регистрации.</span>
      </a>
     </li>
     </ul>
   <?endif;?>
</div>
<?endforeach;?>

It turned out that it does not work and download is available to all users. I pulled this code from the infoblock and posted it on the page - it works! In what there can be a business, prompt, please?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Satir01, 2015-06-26
@Satir01

Solution: disable caching.
The component template is cached and therefore shown equally to both authorized and unauthorized users.

A
Artem Soshnikov, 2015-06-25
@artem90

To determine the authorization for the current user, you must use the global variable $USER

global $USER;
if ($USER->IsAuthorized()) echo "Вы авторизованы!";

https://dev.1c-bitrix.ru/api_help/main/reference/c...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question