guiags
Posts: 29
|
| Posted: 02/10/2010, 10:02 AM |
|
Hi everybody,
I am new in this forum but and i would like you to help me. Please forgive my english, i am a french speaking man.
Ok!
I am now working on an application with user access. My problem is that i want the session of the connected user to close if he makes 5 min without any activity on the application.
I know that your are clever and you will find the answer for me.
Thank you very much
|
 |
 |
code2go
Posts: 13
|
| Posted: 02/10/2010, 10:26 AM |
|
I put this piece of code in my common.php:
$i_time = 5;
//now let`s format the time
$hour = date('H');
$mins = date('i');
$sec = date('s');
$mon = date('m');
$day = date('d');
$year = date('Y');
// this will create the time-stamp
$current_time = mktime($hour,$mins,$sec,$mon,$day,$year);
// and this line will make timeout
$timeout = mktime($hour,$mins+$i_time,$sec,$mon,$day,$year);
// if TIMEOUT session variable does not exist let`s create it
if(!CCGetSession('TIMEOUT'))
{
CCSetSession('TIMEOUT',$timeout);
}
// now let`s do the checking to test if the user has been active
if(CCGetSession('TIMEOUT') < $current_time){
// if not he/she will redirected to the page specified below
header('Location: ' . 'login.php');
}
// this line below is very import because this will refresh the timeout anytime the user navigate
// thru the application
CCSetSession('TIMEOUT',$timeout);
|
 |
 |
datadoit
|
| Posted: 02/10/2010, 11:50 AM |
|
http://prajapatinilesh.wordpress.com/2009/01/14/manuall...ut-php-session/
|
|
|
 |
guiags
Posts: 29
|
| Posted: 02/11/2010, 1:58 AM |
|
WOOOW!!!!!!
thank you very much code2go; it walk properly, i just add this instruction " CCLogoutUser();" and remove the line " header('Location: ' . 'login.php'); " (because when the user is logout, he is automatically redirect to a specific page i made (i used authentication builder to make an "Logout action on the page")).
So, my final code is:
$i_time = 5;
//now let`s format the time
$hour = date('H');
$mins = date('i');
$sec = date('s');
$mon = date('m');
$day = date('d');
$year = date('Y');
// this will create the time-stamp
$current_time = mktime($hour,$mins,$sec,$mon,$day,$year);
// and this line will make timeout
$timeout = mktime($hour,$mins+$i_time,$sec,$mon,$day,$year);
// if TIMEOUT session variable does not exist let`s create it
if(!CCGetSession('TIMEOUT'))
{
CCSetSession('TIMEOUT',$timeout);
}
// now let`s do the checking to test if the user has been active
if(CCGetSession('TIMEOUT') < $current_time){
// if not he/she will redirected to the page specified below
CCLogoutUser();
}
// this line below is very import because this will refresh the timeout anytime the user navigate
// thru the application
CCSetSession('TIMEOUT',$timeout);
Thank you very much.
|
 |
 |
guiags
Posts: 29
|
| Posted: 02/11/2010, 2:00 AM |
|
Quote guiags:
WOOOW!!!!!!
thank you very much code2go; it walk properly, i just add this instruction " CCLogoutUser();" and remove the line " header('Location: ' . 'login.php'); " (because when the user is logout, he is automatically redirect to a specific page i made (i used authentication builder to make an "Logout action on the page")).
So, my final code is:
$i_time = 5;
//now let`s format the time
$hour = date('H');
$mins = date('i');
$sec = date('s');
$mon = date('m');
$day = date('d');
$year = date('Y');
// this will create the time-stamp
$current_time = mktime($hour,$mins,$sec,$mon,$day,$year);
// and this line will make timeout
$timeout = mktime($hour,$mins+$i_time,$sec,$mon,$day,$year);
// if TIMEOUT session variable does not exist let`s create it
if(!CCGetSession('TIMEOUT'))
{
CCSetSession('TIMEOUT',$timeout);
}
// now let`s do the checking to test if the user has been active
if(CCGetSession('TIMEOUT') < $current_time){
// if not he/she will redirected to the page specified below
CCLogoutUser();
}
// this line below is very import because this will refresh the timeout anytime the user navigate
// thru the application
CCSetSession('TIMEOUT',$timeout);
Thank you very much.
|
 |
 |
RoyBaird
Posts: 115
|
| Posted: 02/23/2010, 5:27 AM |
|
A problem with this. Once the user is logged out, I cannot log back in. I called CClogoutUser that is supposed to delete session variables. Do I need to reset something in the common after the CCLogoutUser call?
_________________
Roy |
 |
 |
guiags
Posts: 29
|
| Posted: 02/23/2010, 6:07 AM |
|
Hi Roy!
I don't get you problem very well.
Do you want to log back in by clicking on "back" button of your browser or you are saying that after logout, the user can't log in again in the login form?
Please explain
I hope that you can understand something in this bad english
|
 |
 |
datadoit
|
| Posted: 02/23/2010, 7:24 AM |
|
You should really -really- let the web server manage your session
inactivity. Messing around in Common.php is bad news, with a 100%
headache-later rate.
|
|
|
 |
RoyBaird
Posts: 115
|
| Posted: 02/23/2010, 12:01 PM |
|
After the time expires, and I go to log back on, I can't. CClogOutUser should delete the session variables and let me log back in, but it looks like it does not. I only set one page to "timeout" as a test. To log back in, I had to take the code out of the common.php file. I will keep playing with it until I find an answer.
Thanks guiags!
_________________
Roy |
 |
 |
guiags
Posts: 29
|
| Posted: 02/24/2010, 1:01 AM |
|
Hi Roy
May be i don't understant your problem very well because of my level in english but i will try to explain you how it walk step by step
1- you create your login form with the authentiaction builder (let say in the file login.php)
2- you create the file mySpace.php which is the page where you rich after authentication success
3- In mySpace.php, you use the authentication builder to create a "Logout Link to custom Page" and you specify login.php as that custom page
4- In login.php, you use the authentication builder for a 2nd time, but now is to create "Logout action on this Page"
5- You adjust your common.php as shown in my previous post.
It is suppose to walk and i hope this description will help you.
|
 |
 |
|