title: Hide login link when logged in
body: <p>My website welcome page has got a link to login and one to logout. I want to know how to only show the logout link when the user is logged in and the other way around?</p>
  
  <p>index.php code:</p>
  
  <pre><code>&lt;?php require_once('Connections/PAPCon.php'); ?&gt;
  &lt;?php
  //initialize the session
  if (!isset($_SESSION)) {
    session_start();
  }
  
  // ** Logout the current user. **
  $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
  if ((isset($_SERVER['QUERY_STRING'])) &amp;&amp; ($_SERVER['QUERY_STRING'] != "")){
    $logoutAction .="&amp;". htmlentities($_SERVER['QUERY_STRING']);
  }
  
  if ((isset($_GET['doLogout'])) &amp;&amp;($_GET['doLogout']=="true")){
    //to fully log out a visitor we need to clear the session varialbles
    $_SESSION['MM_Username'] = NULL;
    $_SESSION['MM_UserGroup'] = NULL;
    $_SESSION['PrevUrl'] = NULL;
    unset($_SESSION['MM_Username']);
    unset($_SESSION['MM_UserGroup']);
    unset($_SESSION['PrevUrl']);
  
    $logoutGoTo = "login.php";
    if ($logoutGoTo) {
      header("Location: $logoutGoTo");
      exit;
    }
  }
  ?&gt;
  &lt;?php
  if (!function_exists("GetSQLValueString")) {
  function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  {
    if (PHP_VERSION &lt; 6) {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    }
  
    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  
    switch ($theType) {
      case "text":
        $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
        break;    
      case "long":
      case "int":
        $theValue = ($theValue != "") ? intval($theValue) : "NULL";
        break;
      case "double":
        $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
        break;
      case "date":
        $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
        break;
      case "defined":
        $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
        break;
    }
    return $theValue;
  }
  }
  
  mysql_select_db($database_PAPCon, $PAPCon);
  $query_Users = "SELECT * FROM tbl_utilizadores";
  $Users = mysql_query($query_Users, $PAPCon) or die(mysql_error());
  $row_Users = mysql_fetch_assoc($Users);
  $totalRows_Users = mysql_num_rows($Users);
  ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" &gt;
  &lt;head&gt;
      &lt;meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /&gt;
      &lt;title&gt;RelPro&lt;/title&gt;
  &lt;link rel="stylesheet" type="text/css" media="screen" href="style.css" /&gt;
  &lt;style type="text/css"&gt;
  #container #intro #pageHeader h1 {
      font-size: 4em;
  }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="container"&gt;
      &lt;div id="intro"&gt;
        &lt;div id="pageHeader" style="padding: 20px 0 0 50px;"&gt;
              &lt;h1&gt;RelPro&lt;/h1&gt;&lt;h2&gt;&amp;nbsp;&lt;/h2&gt;
              &lt;h2&gt;&lt;span&gt;by: M&amp;aacute;rio Hon&amp;oacute;rio 12&amp;ordm;PI N&amp;ordm;6&lt;/span&gt;&lt;/h2&gt;
          &lt;h2&gt;&lt;div style="position: absolute; left: 944px; top: 152px; height: 100px;"&gt;&lt;img src="Logo PAP 2.png" alt="" width="230" height="187" /&gt;&lt;/div&gt;&lt;/h2&gt;
          &lt;/div&gt;
  
          &lt;div id="preamble"&gt;
              &lt;h3&gt;&lt;span&gt;Acerca da RelPro&lt;/span&gt;&lt;/h3&gt;
              &lt;p class="p1"&gt;Este website foi criado no &amp;acirc;mbito do Curso Profissional de T&amp;eacute;cnico de Gest&amp;atilde;o de Equipamentos Inform&amp;aacute;ticos de forma a avaliar toda a aprendizagem realizada. Foi concebido de forma a facilitar o acesso a relat&amp;oacute;rios de projectos de final de curso de v&amp;aacute;rias &amp;aacute;reas a todos os interessados. &amp;Eacute; um website de f&amp;aacute;cil acesso, simples design e produzido em linguagem PHP, MySQL e HTML.&lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div id="supportingText"&gt;&lt;/div&gt;
      &lt;div id="footer"&gt;&lt;/div&gt;
  
      &lt;div id="linkList"&gt;
          &lt;div id="linkList2"&gt;
              &lt;div id="lselect"&gt;
                  &lt;h3 class="select"&gt;&lt;span&gt;Sec&amp;ccedil;&amp;otilde;es:&lt;/span&gt;&lt;/h3&gt;
                  &lt;ul&gt;
                      &lt;li&gt;RelPro&lt;/li&gt;
                      &lt;li&gt;&lt;a href="relatorios.php"&gt;Relat&amp;oacute;rios&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="admin.php"&gt;Admin&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="contactos.php"&gt;Contactos&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="login.php"&gt;Login&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="&lt;?php echo $logoutAction ?&gt;"&gt;Log out&lt;/a&gt;&lt;/li&gt;
                  &lt;/ul&gt;
        &lt;/div&gt;&lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;?php
  mysql_free_result($Users);
  ?&gt;
  </code></pre>
  
  <p>Here is a picture of the section menu where the links are:</p>
  
  <p><img src="https://i.stack.imgur.com/jpt5V.png" alt="enter image description here"></p>
  
  <p>Either hidden or disabled will do.</p>