1

What if I want to have HTML code inside my 'if' statement, and then php code in the 'else' part? What do I do? I have tried this, but with no luck..

<?php

session_start();

if ($_SESSION['bnavn']) : ?>

   'HTML-code'

<?php else : ?>

    'PHP-code'
    
<?php endif: ?>

I have also tried this, but also with no luck:

<?php

    session_start();

    if ($_SESSION['bnavn']) : ?>

       'HTML-code'

    <?php else : ?>

        <?php 'PHP-code' ?>
        
    <?php endif: ?>
Troels
  • 11
  • 1
  • @LukePark yes it does http://php.net/manual/en/control-structures.alternative-syntax.php – rjdown Feb 27 '16 at 23:00
  • Apologies, wasn't aware of this. – Luke Joshua Park Feb 27 '16 at 23:01
  • @Troels read that link above, take note of the semi-colon after the endif – rjdown Feb 27 '16 at 23:02
  • 1
    The second way should work (besides the colon at the end that should be a semi-colon). What is the problem? Why not provide the exact code you are trying with? – trincot Feb 27 '16 at 23:08
  • An entire page is inside the if statement. This page should only be shown if the statement is true, and if not, it should with PHP-code in the 'else' part 'die' like: – Troels Feb 27 '16 at 23:59
  • But despite the fact that I log out, which means the session is destroyed, I am still able to direct to this 'page' referred to before. It should instead output "You are not logged ind!" .. – Troels Feb 28 '16 at 00:01

1 Answers1

0

I have figured it out! I found this link: PHP Session Destroy on Log Out Button

I made the if statement as one of the answers said, and changed my page.html to page.php. I do not know if it have to .php instead of .html, but not it works!

Community
  • 1
  • 1
Troels
  • 11
  • 1