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: ?>

6
  • @LukePark yes it does php.net/manual/en/control-structures.alternative-syntax.php Commented Feb 27, 2016 at 23:00
  • Apologies, wasn't aware of this. Commented Feb 27, 2016 at 23:01
  • @Troels read that link above, take note of the semi-colon after the endif Commented Feb 27, 2016 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? Commented Feb 27, 2016 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: <?php die ("You are not logged in!"); ?> Commented Feb 27, 2016 at 23:59

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.