Jump to content

Login & Logout


Edmhar

Recommended Posts

There is no standard built in feature for this.

 

A simple example would be when a user successfully logs in you set a session variable like this

$_SESSION['logged_in'] = true; 

To work out what link to show you check this session variable's value. If it is set to true then you output the logout link. Otherwise you output the login link. Example

if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) {
   echo '<a href="logout.php">Logout</a>'; // output logout link
} else {
   echo '<a href="login.php">Login</a>';   // output login link
}
Edited by Ch0cu3r
Link to comment
Share on other sites

 

There is no standard built in feature for this.

 

A simple example would be when a user successfully logs in you set a session variable like this

$_SESSION['logged_in'] = true; 

To work out what link to show you check this session variable's value. If it is set to true then you output the logout link. Otherwise you output the login link. Example

if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) {
   echo '<a href="logout.php">Logout</a>'; // output logout link
} else {
   echo '<a href="login.php">Login</a>';   // output login link
}

thanks man your great hahaha 

I love you No homo!  you helping me to finish my Thesis :)

Link to comment
Share on other sites

 

There is no standard built in feature for this.

 

A simple example would be when a user successfully logs in you set a session variable like this

$_SESSION['logged_in'] = true; 

To work out what link to show you check this session variable's value. If it is set to true then you output the logout link. Otherwise you output the login link. Example

if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) {
   echo '<a href="logout.php">Logout</a>'; // output logout link
} else {
   echo '<a href="login.php">Login</a>';   // output login link
}

how about if i put this in html?

Link to comment
Share on other sites

Yes you can surround the if/else with HTML code. So long as the file still has a .php extension and you are starting the session before you output the html.

Example with html

<?php 
session_start(); //start the session before the html
?>
<html>
<head>
  <title>Page title</title>
</head>
<body>

  <div id="container">
    <div id="header">
      <h1>Header</h1>
      <div id="nav">
        <?php
          // output login or logout links here
          if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) {
             echo '<a href="logout.php">Logout</a>'; // output logout link
          } else {
             echo '<a href="login.php">Login</a>';   // output login link
          }
        ?>
      </div>
    </div>
    <div id="content">
       page content 
    </div>  
  </div>

</body>
</html>
Edited by Ch0cu3r
Link to comment
Share on other sites

 

Yes you can surround the if/else with HTML code. So long as the file still has a .php extension and you are starting the session before you output the html.

Example with html

<?php 
session_start(); //start the session before the html
?>
<html>
<head>
  <title>Page title</title>
</head>
<body>

  <div id="container">
    <div id="header">
      <h1>Header</h1>
      <div id="nav">
        <?php
          // output login or logout links here
          if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) {
             echo '<a href="logout.php">Logout</a>'; // output logout link
          } else {
             echo '<a href="login.php">Login</a>';   // output login link
          }
        ?>
      </div>
    </div>
    <div id="content">
       page content 
    </div>  
  </div>

</body>
</html>

Thank you i passed this problem hahaha 

kindly check my new post simple add and subtract mysql and php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.