I need a script that replaces "login" with "logout" when im logged in and vice versa. Anyone know of a god tutorial that teaches how to do this?

Recommended Answers

All 4 Replies

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.

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>';
}

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

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']);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.