function userLoginMenu() { // array with all menu items $menu = array("login" => "login.php?p=login", "status" => "login.php", "logout" => "login.php?p=logout"); // check if user is logged in or not, alter the menu depending on the result if (userIsAuthenticated()) { unset($menu['login']); } else { unset($menu['status']); unset($menu['logout']); } $html = "<nav class='login right'>"; foreach ($menu as $key => $val) { $html .= "<a href='{$val}'>{$key}</a> "; } $html .= "</nav>"; return $html; }
<?php include "incl/header.php"; ?> <div id="content"> <div class="left borderRight width80""> <?php if (isset($content)) { echo $content; } else { ?> <h1>Status login / logout</h1> <p>Denna webbplats har skyddade delar. Du måste logga in för att komma åt dem.</p> <p>För tillfället är du: <?php if (userIsAuthenticated()) { ?> <strong>inloggad</strong>.</p> <p><a href="?p=logout">Vill du logga ut</a>?</p> <?php } else { ?> <strong>ej inloggad</strong>.</p> <p><a href="?p=login">Vill du logga in</a>?</p> <?php } ?> <?php } ?>