0

So far, I have only the login.html files which has login form, redirects user once logged on and logout function. What I want to do is once a user logs in, they redirect to but their username is displayed on the top of the page. And with the file... I just want it to be able to logout the user. So far on my website, I can login as far as I am concerned, and it redirects once user logs in, but I can login as many times as I want, and I can logout as many times as I want.... It's complicated to sort out and I want to do this without SQL or any other server-side storage (since I am only using HTML local storage).

17
  • 1
    Why do you need to log in if you don't want to use any server-side storage? Why does logging in matter? Commented Dec 15, 2016 at 21:28
  • Use PHP to prevent displaying the login form. Also, use PHP to prevent someone from logging in again if they are already logged in. if ( $_SESSION['username'] ) { //... redirect / show "already logged in" message }; Commented Dec 15, 2016 at 21:31
  • Well look, i literally just want the user to be able to log in, and once they are logged in, their username is displayed on the homepage... and i want a logout button to be displayed so once it's clicked, the user logs out.. Commented Dec 15, 2016 at 21:31
  • Can anyone alter my current codes and show me how it is done, i just want to know, because i am clueless in going forward with this Commented Dec 15, 2016 at 21:32
  • @A.Adams in your Gamewebsite.php page (where you finally redirect after successful login), just echo out $_SESSION['username'] Commented Dec 15, 2016 at 21:34

3 Answers 3

2

You have to remove the session of username in logout code

unset($_SESSION['username']);

Hope this helps..If not,It would be better if you could provide the code, so that the problem can be sorted out

Sign up to request clarification or add additional context in comments.

Comments

1

WRITE THIS ALL IN TOP PAGE

IN YOUR LOGIN PAGE

       <?php
        session_start();
        if (isset($_POST["submit"])) {
            $username = $_POST["username"];
            $_SESSION["username"] = $username;

        header('Refresh: 5; URL=GameWebsite.php')
        }
        ?>

IN YOUR LOGOUT PAGE

if(isset($_SESSION['username']))
    {
  session_start();
  session_unset();
  session_destroy();
  //Then you may redirect to the login page if you want after sometime.
  echo " You have successfully logged out... You will be redirected back to the login page in a moment. ";
 header('Refresh: 5; URL=login.php'); 
    }
     else
    {
       header("Location:login.php"); // HERE WHEN USER NO HAVE SESSION
    }

IN ANOTHER PAGES YOU CHECK

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

}else
{
 header("Location:login.php"); // HERE WHEN USER NO HAVE SESSION
}

Comments

0

in your login page write on top

if(isset($_SESSION['username']))
{
header('Refresh: 5; URL=GameWebsite.html')
}

In your logout.php write

if(isset($_SESSION['username']))
    {
   session_start();
  session_unset();
  session_destroy();
  //Then you may redirect to the login page if you want after sometime.
  echo " You have successfully logged out... You will be redirected back to the login page in a moment. ";
 header('Refresh: 5; URL=Login.html'); 
    }
     else
    {
       header("Location: login.php");
    }

18 Comments

when you loged in only that time you can see logout button you can check it like this <?php isset($_SESSION['username']{?> HERE YOUR LOGOUT BUTTON <?php}?> When user click on logout button he redirect into logout php and int ther he see your message
<?php isset($_SESSION['username'] { ?> <a href="logout.php" style="position:absolute;top:120px;right:35px "> Click here to logout </a> <?php } ?>
what you have in that line?
<?php isset($_SESSION['username'] { ?> <a href="logout.php" style="position:absolute;top:120px;right:35px "> Click here to logout </a> <?php } ?>
can you send me 3 files login logout and GameWebsite php ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.