3
Contributors
4
Replies
29
Views
4 Years
Discussion Span
Last Post by Octet
3

Assuming you have created a session then all you need to do is check whether or not it has been set, like so:

<?php

if(isset($_SESSION['SESSION_NAME'])) {

    ?> <a href = "/Logout.php" > Logout </a> <?php

}

if(!isset($_SESSION['SESSION_NAME'])) {

    ?> <a href = "/Login.php" > Login </a> <?php

}

?>

What this is doing is saying, if a session has been created then it should display logout but if it hasn't then it shall display login.

Edited by Octet

1

AHarrisGsy is right, upvote for that. I'll just to simplyfy it a little bit:

if(isset($_SESSION['SESSION_NAME'])) {
    echo '<a href = "/Logout.php" > Logout </a>';
} else {
    echo '<a href = "/Login.php" > Login </a>';
}

Edited by broj1

0

sweet thanks for the replies. How would i set up that script to also logout when logout is clicked?

0

Simple unset your session, so when it goes to your Logout.php page you would have something like this:

session_start();

unset($_SESSION['SESSION_NAME']);

Edited by Octet

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.