0

I have this code in my html file which is rendered by PHP:

<div>
  <?php if($SESSION.userName=='UNSET'):  ?>
     User is not logged in
  <?php else: ?>
     user is logged in: user name is: {{ @SESSION.userName }}
  <?php endif; ?>
</div>
<div> test  {{ @SESSION.userName }} 
</div>

The above code generates this output:

User is not logged in user is logged in: user name is: a
test a

This apparently means that the if statement is not calculated.

What is the problem and how I can fix it? I am new to PHP (just started today!)

Note: logged username is a

Edit1

The page is rendered using this function from an index.php file:

$f3->route(
  'GET @home:/',
  function ($f3) {
    $f3->set('html_title', 'MyServer');
    $f3->set('content', 'index.html');
    echo Template::instance()->render('layout.php');
  }
mans
  • 17,104
  • 45
  • 172
  • 321

1 Answers1

1

As you mentioned you are using f3 template engine, according to its documentation you can use this for your condition:

<check if="{{ @SESSION.userName=='UNSET' }}">
    <true>
        <div>User is not logged in</div>
    </true>
    <false>
        <div> user is logged in: user name is: {{ @SESSION.userName }}</div>
    </false>
</check>
keyhan
  • 522
  • 1
  • 7