HTML & PHP -Turn a log in button out

0

I have my code in PHP created for both log in and log out, I confess that I read several articles in google how to turn a log in button but I confess that it did not help at all, I'm here to ask if anyone can enlighten me how. My page index (SEE PHOTO) has a button called member area that I would like to become a button called log out when the user logs in. Updatedcode:

[![<!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">    
  <link rel="stylesheet" type="text/css" href="index.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>

<body>

    <nav class="navigation">
  <ul class="mainmenu
             ">
      <li><a href="index.html"><i class="material-icons">home</i></a></li>
    <li><a href="">Books Categories</a>
      <ul class="submenu">
        <li><a href="bookcomputing.php">Computing</a></li>
        <li><a href="bookromance.php">Romance</a></li>
        <li><a href="bookfiction.php">Fiction</a></li>
         <li><a href="booknonfiction.php">Non-Fiction</a></li>  
      </ul>
    </li>
    <li><a href="contact.html">Contact us</a></li>
  </ul>
</nav>
    <div id="memberarea">
      <?php

if (!isset($_SESSION\['email'\])) {
    echo "<a href='memberarea.html'>Member area</a>";
} else {
    echo "<a href='logout.php'>Log out</a>"; 
} 

?>
      <a href="adminarea.php"><span class="glyphicon glyphicon-lock"></span> Admin area</a>
</div>
    <form action="search.php" method="GET" id="search">
        <input type="text" name="query" placeholder="author's name, title">
        <input type="submit" value="Search">
    </form>
<p> Welcome to Galaxy Book Store website, this website was created for people who really enjoy reading all sort of books.</p> 
<p>Here you can find a huge amount of books.</p>
</body>
</html>
<footer>
    <p> &#174; Galaxy Books Store</p>

</footer>][2]][2]
    
asked by anonymous 07.05.2017 / 12:26

2 answers

3

Change the " Member Area " to something like:

<?php

if (isset($_SESSION['email'])) {
    echo "<a href='logout.php'>Log out</a>";
} else {
    echo "<a href='login.php'>Member Area</a>"; 
} 

?>

Running

If the session email exists, it will display " Log Out ". If it does not exist, it will display " Member Area ".

    
07.05.2017 / 16:08
1

Try using the PHP session schema.

When the user is logged in, you should create a session something like this:

<?php
    session_start();
    $_SESSION['login'] = 'login do usuário'
?>

This will make the browser aware that the user has logged in.

After this, you should put a session check where you want to change the button:

<div id="memberarea">
    <?php
        if(isset($_SESSION['login'])) {
            echo "<a href='logout.php'>Log out</a>";
        }else {
            echo "<a href='login.php'>Login</a>"; 
        }
    ?>
</div>
    
09.05.2017 / 21:58