When using PHP code and HTML throughout the whole page of a website, is it quicker to state a condition than define the whole page, or keep going back to that condition at different parts of the page? For example:
<?php if(isset($_SESSION['token'])) { ?>
<html> Lots of HTML </html>
<?php } else if (!isset($_SESSION['token'])) { ?>
<html> Lots of HTML </html> <?php } ?>
So here I'm just basically defining the whole page twice with different stuff depending on whether the user is logged in or not.
Or I could do..
<?php if(isset($_SESSION['token'])) $loggedIn = true;
else if (!isset($_SESSION['token'])) $LoggedIn = false; ?>
<html>
Some HTML stuff ...
<?php if($LoggedIn == true) echo "<div>You are now logged in</div>";
else if($LoggedIn == false) echo "<div>Please log in to continue</div>"; ?>
Some more HTML ...
<?php if($LoggedIn == true) // Etc. ?>
</html>
And here I'm just checking back to whether the user is logged in or not within the same HTML tags and displaying the appropriate content.
Also, could anyone tell me whether its better to echo HTML, or just cut off the PHP, use normal HTML and then reopen PHP and close the bracket.
I tried to be as clear as possible but was finding it hard.