redirect a user to a logout page if no action taken...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adeelzia
Forum Newbie
Posts: 22
Joined: Thu Jul 06, 2006 5:31 pm

redirect a user to a logout page if no action taken...

Post by adeelzia »

Can there be a way that if the user hasn't dealt with a page for about 30 minutes could be sent to a logout page where the session is finished.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

A Javascript timeout or meta redirect could do it, but I wouldn't go about this in that fashion.

viewtopic.php?t=53558 may be of interest.
adeelzia
Forum Newbie
Posts: 22
Joined: Thu Jul 06, 2006 5:31 pm

Post by adeelzia »

No use,can't there be another way to do it.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

feyd wrote:A Javascript timeout or meta redirect could do it
:roll: That is your only option(s)
mikesmith76
Forum Commoner
Posts: 34
Joined: Fri Aug 25, 2006 7:10 am
Location: Manchester, UK

Post by mikesmith76 »

Have you considered what will happen when someone just closes the browser window. I would think this would be a lot more likely than soneone leaving the window open for half an hour without doing anythign with it
adeelzia
Forum Newbie
Posts: 22
Joined: Thu Jul 06, 2006 5:31 pm

Post by adeelzia »

I just want that if a session timeout is met(no one uses the page within that time) the user should be loggedout automatically,dont tell me this and that :( if any one has the solution hez most welcome :D
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

what is wrong with the three solutions feyd posted? :roll:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If you are checking for a current session (like you should be doing) then this should be easily handled for every page load. But it won't be discovered until the user submits a page request to the browser. If you are looking to do this real time (like it has been 30 minutes, the page will now log you out) then you have to use a client side technology.
adeelzia
Forum Newbie
Posts: 22
Joined: Thu Jul 06, 2006 5:31 pm

Post by adeelzia »

The solutions that fyed posted have been tried but they don't seem to work, and Mr Everah I don't want that the user should be specially loggedout automatically if 30 minutes are gone, I'm just saying that if the page is open for 30 minutes and there has been no traffic what so ever than on clicking something after 30 minutes on that page the user should be sent to the login page,.................any solution on that is welcomed..........
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

the thread feyd posted tellls you how to do that. What have you tried.... show us your code where you tried what he said and maybe we can help you get it working.
adeelzia
Forum Newbie
Posts: 22
Joined: Thu Jul 06, 2006 5:31 pm

Post by adeelzia »

Code: Select all

<?
         session_start();

         if(!isset($_SESSION['userId']))
         {
             header("Location: userlogin.php");
         }
         else
         {

             $userId = $_SESSION['userId'];
             $userName = $_SESSION['userName'];
             $userPassword = $_SESSION['userPassword'];
         }


?>

Code: Select all

<html>
<head>
<title>User Activities</title>

Code: Select all

//This is the point where I am using the meta tags but it doesn't logout to the required page after the time

Code: Select all

<META HTTP-EQUIV="REFRESH" CONTENT="300;userlogout.php">

<!-- Fireworks MX Dreamweaver MX target.  Created Fri Jan 06 16:18:49 GMT+0500 (West Asia Standard Time) 2006-->
</head>
<body bgcolor="#ffffff" WIDTH=750 BORDER=0 CELLPADDING=0 CELLSPACING=0 TOPMARGIN=0>

<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="750">
<!-- fwtable fwsrc="1_1 copy.jpg" fwbase="1_1.jpg" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="0" -->
  <tr>
   <td><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>
   <td><img src="images/spacer.gif" width="16" height="1" border="0" alt=""></td>
   <td><img src="images/spacer.gif" width="710" height="1" border="0" alt=""></td>
   <td><img src="images/spacer.gif" width="23" height="1" border="0" alt=""></td>
   <td><img src="images/spacer.gif" width="1" height="1" border="0" alt=""></td>  </tr>

  <tr>
   <td><img src="images/spacer.gif" width="1" height="221" border="0" alt=""></td>
   <td colspan="3"><font face="Verdana"><map name="FPMap0">
    <area href="index.php" shape="rect" coords="18, 179, 134, 217">
    <area href="aboutUs.php" shape="rect" coords="159, 179, 275, 213">
    <area href="help.php" shape="rect" coords="299, 180, 407, 214">
    <area href="resources.php" shape="rect" coords="429, 180, 556, 218">
    <area href="contactUs.php" shape="rect" coords="573, 181, 729, 213"></map><img border="0" src="images/Banner.JPG" width="750" height="221" usemap="#FPMap0"></font></td>
  </tr>
  <tr>
   <td rowspan="2" colspan="2" background="images/1_1_r2_c1.jpg">&nbsp;</td>
   <td background="images/userScreen.jpg">&nbsp;
    <p>&nbsp; <font face="Verdana"> Welcome, <?php echo strtoupper($userName); ?></font></p>
   </td>
   <td rowspan="2" background="images/1_1_r2_c4.jpg">&nbsp;</td>
  </tr>
  <tr>
   <td>
    <p align="center">&nbsp;
    <p align="center"><font face="Verdana" size="4">Pending Activity Forms</font>&nbsp;
    <table id="table4" style="BORDER-COLLAPSE: collapse" borderColor="#111111" cellSpacing="0" cellPadding="0" width="100%" border="0">
      <tbody>
        <tr>
          <td width="100%">
            <p align="right"><font face="Verdana"><span style="FONT-SIZE: 8pt; FONT-STYLE: italic">&nbsp;Activity
            Monitor</span></font>&nbsp;&nbsp;&nbsp;</p>
          </td>
        </tr>
      </tbody>
    </table>
    <hr color="#000000" SIZE="1">
    <form method="POST" action="userPa.php">
  <b><font face="Verdana" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The Pending Activity Forms for "

Code: Select all

<?php echo strtoupper($userName); ?>

Code: Select all

" are given below: </font></b><br>

            <font face="Verdana" size="2">

Code: Select all

<?

            //  Coding for Pending Activites

            $previousSunday = strtotime("previous sunday");
            $prevSunday = date('Y-m-d', $previousSunday);


            include ("include/database.php");


            $link = mysql_connect($dbServer, $dbUser, $dbPassword);

            if (!$link)
            {
                    die('Could not connect: ' . mysql_error());
            }
            else
            {

                    mysql_select_db ("project", $link);
                                                                                                                        
                    $query = "SELECT formId,date_format(frmDt, '%d %b %Y') AS formattedFrmDt FROM activityForm WHERE formStatus = 'pending' AND empId='$userId' AND frmDt>='$prevSunday'";
                    $result = mysql_query ($query, $link);


                    while ($query_data = mysql_fetch_array($result))
                    {

                    $formId = $query_data["formId"];
                    $frmDt = $query_data["formattedFrmDt"];


             ?>

Code: Select all

<br>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="activityForm2.php?formId=

Code: Select all

<?echo "$formId";?>
">

Code: Select all

<?

                       echo $frmDt;

                    ?>

Code: Select all

</a>
                    <br>

Code: Select all

<?




             }

             mysql_free_result($result);

             mysql_close($link);

             }



             ?>

Code: Select all

<p align="center">
             <br><br>
             <input type="submit" value="back" name="back">


             <br><br><br><br><br>

  <tr>
   <td colspan="4"><font face="Verdana"><map name="FPMap1">
    <area href="index.php" shape="rect" coords="71, 21, 123, 41">
    <area href="aboutUs.php" shape="rect" coords="145, 19, 226, 39">
    <area href="help.php" shape="rect" coords="252, 18, 300, 39">
    <area href="contactUs.php" shape="rect" coords="325, 17, 426, 39"></map><img name="n1_1_r4_c1" src="images/1_1_r4_c1.jpg" width="750" height="49" border="0" alt="" usemap="#FPMap1"></font></td>
   
  </tr>
</table>
</form>
</body>
</html>
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

did you read the thread feyd posted? If you read it, you'll see that you need to store the last user activity (by means of a timestamp) in the session, and on each new page request you just check to see if a certain amount of seconds have passed, and if so, kill the session and redirect... c'mon you can do it! :D
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You might have problems with the session.gc_max_lifetime default setting (24 minutes I blieve) if you are using timestamps and want the timeout to be 30 minutes. Although I would say that 30 minutes may be a little too long to leave a session unattended (unless you are doing lengthy content publishing or other things that require an excessive amount of time). I limit my unattended sessions to 10 minutes tops.
Post Reply