Page 1 of 1

php session timeout warning message

Posted: Thu Oct 30, 2008 11:17 am
by pavanpuligandla
hii..

i'm ending the session after 30 minutes of inactivity in my php page containing 3 frames using:

Code: Select all

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; CHARSET=UTF-8">
<META HTTP-EQUIV="CONTENT-SCRIPT-TYPE" CONTENT="text/javascript">
<META HTTP-EQUIV="CONTENT-STYLE-TYPE" CONTENT="text/css">
 
<META HTTP-EQUIV="EXPIRES" CONTENT="-1">
<META HTTP-EQUIV="Refresh" CONTENT="1800; 
URL=http://localhost/MyDreamProject/sessiontimeout.php">
so i'm displaying a warning message using javascript to alert the user that his/her session is about to expire in 2 minutes, to continue click ok and to end the session click cancel.

herez my javascript code for tht.

Code: Select all

<script language="JavaScript">
 
    var a, pageTimer;  //declare var
 
    function startClock()
    {
    pageTimer = 0;  //start at 0
    a = window.setInterval("tick()",60000);  //run func tick every minute....  (60 sec x 1000 ms = 1min)
    }
 
    function tick()
    {
    pageTimer++;  //increment timer
    if (pageTimer == 15) {warnuser()};  //if 28 min without activity
    }
 
    function warnuser()
    {
        if (confirm("There has been no activity for some time.\nClick 'OK' if you wish to continue your session,\nor click 'Cancel' to log out.\nFor your security if you are unable to respond to this message\nwithin two minutes you will be logged out automatically."))
        {
            
           [b] refreshme.document.location.href = "http://localhost/Project/navigation.php"[/b]
        }
        else
        {
        document.location.href="http://localhost/Project/logout.php"
        }
    }
</script>
</head>
<body BGCOLOR="#F8F5EF" class="PSPAGE" onload="startClock();">
<iframe id="refreshme" style="DISPLAY: none; LEFT: 200px; POSITION: absolute; TOP: 40px" name="theframe" width="40" height="0">
    </iframe>
 
but when i click ok, the session is not carrying over and getting ended after 2 minutes.
can anyone tel me how to avoid this.
i think there is an error enclosed in BOLD quoted code.
Many Thanks,
Pavan.P

Re: php session timeout warning message

Posted: Thu Oct 30, 2008 12:10 pm
by Hannes2k
Hi,
okay:
refreshme.document.location.href = "http://localhost/Project/navigation.php"

Please use there getElementById or something like this. Is the content in the i-frame reloaded? And do you call session_start() in navigation.php?
If your answer is 'yes' to all the questions, check if your browser sends the right Session ID (use e.g. Live HTTP Header and there your browser should send a cookie with his SID).

Re: php session timeout warning message

Posted: Thu Oct 30, 2008 12:33 pm
by pavanpuligandla
hii,

refreshme.document.location.href = "http://localhost/Project/navigation.php"

i'm writing this script in navigation.php itself.
if timelimit reaches 28 minutes, the warn() script will alerts the user that the session is about to expire.

as i'm using 3 frames in my php page, i'm including this script in one of 3 pages.
yes, SID is working fine no probs with it..
the problem is with the above piece of code only,
i think i've to ping the server to continue the session if user cliks OK.