Jump to content
MakeWebGames

Sessions?


OutcasT

Recommended Posts

How can I make my game log out someone after some inactivity?

Currently if someone goes off the page and returns later, they are still signed in.

How can I change that?

Also, if they access the page that it logs in to, it comes up but everything is blank, how can I redirect them?

Link to comment
Share on other sites

a simple way to do this is with javascript i.e.

<script>
   var redirectAfter = 30; // Mins
   var redirectTo = 'logout.php';
   setTimeout(function () {document.location = redirectTo;}, (redirectAfter*60000));
</script>

What this does is on each page load it will start a timer (time depending on the redirectAfter variable), once the timer is completed it will redirect to a page. I have redirected it to logout.php, this should then log the user out and show the login page. You could make a timeout page and redirect it to that but that is up to you.

Edited by Dayo
Link to comment
Share on other sites

a simple way to do this is with javascript i.e.

 

<script>
   var redirectAfter = 30; // Mins
   var redirectTo = 'logout.php';
   setTimeout(function () {document.location = redirectTo;}, (redirectAfter*60000));
</script>

 

What this does is on each page load it will start a timer (time depending on the redirectAfter variable), once the timer is completed it will redirect to a page. I have redirected it to logout.php, this should then log the user out and show the login page. You could make a timeout page and redirect it to that but that is up to you.

 

I will try that but how can I make it so people can access the main page without being logged in. they cant do anything but access it. how can I redirect then back to the login page?

Link to comment
Share on other sites

I will try that but how can I make it so people can access the main page without being logged in. they cant do anything but access it. how can I redirect then back to the login page?

[MENTION=70114]OutcasT[/MENTION] can you define what the main page is?

Link to comment
Share on other sites

a simple way to do this is with javascript i.e.

 

<script>
   var redirectAfter = 30; // Mins
   var redirectTo = 'logout.php';
   setTimeout(function () {document.location = redirectTo;}, (redirectAfter*60000));
</script>

 

What this does is on each page load it will start a timer (time depending on the redirectAfter variable), once the timer is completed it will redirect to a page. I have redirected it to logout.php, this should then log the user out and show the login page. You could make a timeout page and redirect it to that but that is up to you.

Off Topic

Ha! So simple and for all these years I've been wondering how to do it, how did I not think of this. Thanks! :)

On Topic

session_unset();

session_destroy();

Make sure you have checks on your "main" page or an authentication page which is included in that PHP file.

 

if(!isset($_SESSION['sessionName']) || empty(trim($_SESSION['sessionName'])) || $_SESSION['sessionName'] == "") {
   // Redirect to login page and give them error.
   header("refresh:3; url=login.php");
   return;
} else {
   // Session is set, redirect to "main" page
   header("Location: main.php");
   return;
}
Edited by Script47
Link to comment
Share on other sites

[MENTION=65371]sniko[/MENTION]

My main page is a page with 3 frames.

- One is the players stats (this refreshes to update)

- Two is the navigation, where all the pages are linked from

- Three is the main page where the action happens

Edited by OutcasT
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...