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
}
Link to comment
https://forums.phpfreaks.com/topic/283509-login-logout/#findComment-1456505
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
https://forums.phpfreaks.com/topic/283509-login-logout/#findComment-1456512
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
https://forums.phpfreaks.com/topic/283509-login-logout/#findComment-1456522
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>
Link to comment
https://forums.phpfreaks.com/topic/283509-login-logout/#findComment-1456524
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
https://forums.phpfreaks.com/topic/283509-login-logout/#findComment-1456621
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.