Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6781019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:34:29+00:00 2026-05-26T16:34:29+00:00

When you click login, it should then display the logout button. Clicking the logout

  • 0

When you click login, it should then display the logout button. Clicking the logout button should make it display the login options again. Currently it just keeps sitting on the login window even though it creates a session and fills it with the right information in my server.

I am not sure why my code is not working. I had it working, then it suddenly stopped and I am not sure what I changed. Also, I am aware that this is not using a database and that I should be using one, but the assignment calls to not use one.

Here is index.php:

<?php

    session_start();
    if(empty($_SESSION['email']))
    {
        include("includes/login.php");
    }
    else 
    {
        include("includes/logout.php");
    }

?>

Here is my login.php:

<form id="login" method="post" action="index.php">
    <input name="email" type="email" placeholder="Email@rit.edu" required="required">
    <input name="password" type="password" placeholder="Password" required="required">
    <input class="button" name="submit" type="submit" value="Submit">
</form>

<?php
    //if someone tries to log in
    if (isset($_POST['email']) && isset($_POST['password']))
    {
        $email=($_POST['email']);
        $password=sha1($_POST['password']);

        $users = file('includes/users.php', FILE_IGNORE_NEW_LINES);

        for($i=0;$i<count($users);$i++)
        {
            $user = explode(',', $users[$i]);
            if($user[0] === $email && $user[1] === $password)
            {
                session_start();
                $_SESSION['email']=$user[0];
                $_SESSION['pass']=$user[1];
                $_SESSION['name']="$user[2] $user[3]";
                $_SESSION['admon']=$user[4];
            }
        }
    }   
?>

Here is logout.php:

<form id="login" method="post" action="index.php">
    <input name="logout" type="submit" value="logout" />
</form>

<?php
    if($_POST['logout'] === 'logout')
    {
        session_destroy();
    }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:34:30+00:00Added an answer on May 26, 2026 at 4:34 pm

    In your index.php, you check if the user has already logged in:

    if(empty($_SESSION['email']))
    

    If not, you include the login page, otherwise the logout. But if you just submitted your form, SESSION[’email’] is still empty, and you are displaying your form. But you have your login data, so if your details are correct, you will be logged in – and you will see it after a refresh.

    Same is true for your logout – if you submit your logout form, your session will be active for one last request (which destroys it), so the logout page will be seen again. You need to refresh your browser, and the login will appaer.

    To fix both problems, simly add a redirect to the end of both if-s. E.g.:

    if($_POST['logout'] === 'logout')
    {
        session_destroy();
        header('Location: index.php);
    }
    

    This will reload your page after processing the logout, effectively giving you the good result. Do the same to the login, and it will work too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When user click on back button of android device from the login screen then
Example: The user login to the webpage => Click on a button This action
I redirect the user to the login page when user click log out however
I'm using Forms Authentication (and the built in Login controls) and letting users click
Click here to see what I mean.. What could prevent these two from sitting
User click on a link button and it will direct them to a url
I have next situation: I should allow to see Add Rendering button in Page
I have a page with login form (on click, login form slides dowm) and
I want to insert the data in a SQLite table login when a button
On my webpage, I click on a button and it makes a ajax call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.