A.Adams
A.Adams

Reputation: 65

How to create logout without SQL and only PHP?

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

Upvotes: 0

Views: 216

Answers (3)

affaz
affaz

Reputation: 1191

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

Upvotes: 2

Aram Mnatsakanyan
Aram Mnatsakanyan

Reputation: 214

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
}

Upvotes: 1

Aram Mnatsakanyan
Aram Mnatsakanyan

Reputation: 214

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");
    }

Upvotes: 0

Related Questions