Jump to content


Photo

Login & Logout


  • Please log in to reply
6 replies to this topic

#1 Edmhar

Edmhar

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 01 November 2013 - 11:16 AM

i want to post if logged in i want to have echo logout link  if not logged in want to echo login



#2 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 2,101 posts

Posted 01 November 2013 - 11:28 AM

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, 01 November 2013 - 11:30 AM.


#3 Edmhar

Edmhar

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 01 November 2013 - 11:59 AM

 

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 :)



#4 Edmhar

Edmhar

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 01 November 2013 - 01:24 PM

thanks man your great hahaha 
I love you No homo!  you helping me to finish my Thesis :)

how about if will put this in html? 



#5 Edmhar

Edmhar

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 01 November 2013 - 01:25 PM

 

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?



#6 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 2,101 posts

Posted 01 November 2013 - 01:46 PM

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, 01 November 2013 - 01:47 PM.


#7 Edmhar

Edmhar

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 02 November 2013 - 12:56 PM

 

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com