html - CGI::Session Expired cookies and browser refresh -


a user enters page in web application. if cookie expired provide user link login page ask user login again. if clicks logout button cookie set expire in past.

    $cookie = $cgi->cookie(-name=>"cgisessid",-value=>'', -path=>'/',-expires=>'-1d'); 

the cookie being set correctly expire in past seen in page info of browser page doesn't know until click refresh

my $cookie = $cgi->cookie('cgisessid'); if ($cookie){         #show content }else{         $cookie = $cgi->cookie(-name=>'cgisessid', -expires=>'now');         print $cgi->header(-cookie=>$cookie);         print "please log in again ";         print "<a href=\"/login.html\"> login page </a>"; } 

how can force page refresh delete cookie. if redirect page simple button display content if cookie expired.

i have login.pl , login.js set in http://www.ibm.com/developerworks/webservices/library/ws-simplelogin/#loginjs

on logout, can redirect page:

$cookie = $cgi->cookie(-name=>'cgisessid', -expires=>'now'); print $cgi->redirect(-uri => 'http://www.example.com/login', -cookie => $cookie); 

edit: think misunderstood question. sounds want redirect cookie expires. tricky. our user's session expires, leave current page open in browser. unfortunately, our cgi script won't run again until user sends request, refreshing page. , until send request, won't know if session has expired.

one possible solution set page auto refresh using html <meta> tag:

use cgi qw(meta);  print $q->header,       $q->start_html(           -head => meta( { -http_equiv => 'refresh',                            -content => '60;url=http://www.example.com/foo.cgi' } )       ), ... 

this redirect cgi script every 60 seconds, allowing check session again.

on note, there better tools cgi.pm developing web applications in perl: dancer, mojolicious, , catalyst, among others.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -