Hello friends,

Am having a membership website and i need some help. How do i code any login required (member's) page to automatically (log out) request relogin after 5 minutes of idleness of the page? and how do i redirect the member back to page where he was loged out after signing in?

Regards

I'll assume you are using sessions to track your login across pages. Set a session variable called "LastAction" as a timestamp. If the user visits a page, check to see if the LastAction timestamp is less than 5 minutes ago. If so, update it to the current timestamp. If not, log them out and display the login form.

As for the second part of the question, I prefer not creating a "login" page at all. Instead, display the login form on any page that requires a login if the user is not already logged in. When they log in, the login form just redirects to the current page. Peudo-code for an exaple page would be:

Page: myAccount.php

if login form was submitted
    Check login credentials
   If valid, add session variables
if login session doesn't exist OR if session has expired
     Display login form.  On submit, redirect to current page
else
    Display page
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.