473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Session timeout

dear friends...
Can we set time for the session to expire..?
If anybody know...plz send me the code...
Jul 19 '07 #1
2 1225
henryrhenryr
103 100+
Hello

You need to check out this page:

http://www.php.net/manual/en/ref.session.php

It has everything you need to know about sessions. I think you can use session.gc_maxlifetime configuration option.

You can also try:

http://www.php.net/manual/en/functio...kie-params.php

Which is a function to set the cookie parameters (so you can set it to expire as you would a cookie).
Jul 19 '07 #2
unicorn
23
dear friends...
Can we set time for the session to expire..?
If anybody know...plz send me the code...

here is link where you can find lots of examples.
php.net
but i recommend to use cookies and set expiration time read this

or if you need high security and realibility, use your own 'expiration time', i.e. create cookie with value and its expirity date and compare it with datebase.

something like that

login.php ->
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.    $uID = uniqid("");
  4.    $IPaddress = $_SERVER["REMOTE_ADDR"];
  5.    mysql_query("UPDATE user SET uID='$uID',IPaddress='$IPaddress',date='".date("U")."' WHERE username='$username'");
  6.  
  7.  
  8. setcookie("username",$username);
  9. setcookie("uID",$uID);
  10.  
  11.  
  12.  
  13. ?>
  14.  
check authentication ->
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. function issesauth()
  4. {
  5.  
  6. $usi = filter($_COOKIE['username']);
  7. $ida = filter($_COOKIE['uID']);
  8.  
  9. $vaxkakoi = MYSQL_QUERY("SELECT * FROM user WHERE username='$usi' AND uID='$ida' AND activ='Y'");
  10. $chachacha = mysql_fetch_array($vaxkakoi);
  11.              if(!$chachacha){
  12. setcookie("username");
  13. setcookie("uID");
  14.              return false;
  15.              }else{
  16.              $IPserver = $chachacha['IPaddress'];
  17.              $diff = $chachacha['date']+constant("timeLim")-date("U");
  18.              $IPrecent = $_SERVER["REMOTE_ADDR"];
  19.  
  20.  
  21.              if(($IPserver != $IPrecent)||($diff<0)){
  22. setcookie("username");
  23. setcookie("uID");
  24.              return false;
  25.              }else{
  26.              $datu = date("U");
  27. mysql_query("UPDATE user SET date='$datu' WHERE username='$usi'");
  28.              return true;
  29.              }
  30.              }
  31. }else{
  32. setcookie("username");
  33. setcookie("uID");
  34. return false;
  35.  
  36. }
  37.  
  38.  
  39.  
  40. ?>
  41.  
you can use this function to check authorisation of user, and set his login validity period manualy, and it works better... i
of course u need databe where you can store users password, uID (userid) and date (time of login). good luck.
Jul 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Geigho | last post by:
Setting session timeout in web.config file does not seem to have any effect. Any explanation or suggestion will be appreciated.
4
by: DavidS | last post by:
First: There are several ways to confuse one regarding session timeout. (1) web.config - <sessionState timeout="20"> (2) IIS Manager | Internet Information Services | ServerNode | Default Web Site...
8
by: Joe Abou Jaoude | last post by:
hi, I have a web app with forms authentication and a timeout session of 20 mins for security reasons. I recently added a feature that allows users (if they want to) to automatically log in...
11
by: Vishal | last post by:
Hello, can anybody tell me how I can extend the session expiry time? Is it done via code or via IIS? Sorry I am new and dont know about this.
5
by: Just D. | last post by:
Do we have any access to the Session object from a different Session? The idea is to save Session of a current user and then if he logs in again then return the Session back. It's not a problem to...
8
by: bdeviled | last post by:
I am deploying to a web environment that uses load balancing and to insure that sessions persist across servers, the environment uses SQL to manage sessions. The machine.config file determines how...
17
by: jensen bredal | last post by:
Hello, i'm struggling with a somehow badly understood session scenario. I provide acces to my pages based on form authentication using Session cookies. Som of my pages are supposed to be...
4
by: UJ | last post by:
I have a page where the user can upload a video file. As you can guess, this may take a while. Is there a way I can change the session timeout for just this one page? I would also want to change...
25
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
I tried: <sessionState timeout="1"> </sessionState> bounced IIS, and after 1 minute still had a session. ??? -- thanks - dave
6
by: ChrisAtWokingham | last post by:
I have been struggling with unexpected error messages on an ASP.NET system, using SQL and C#. The application draws organisation charts, based on data stored in the SQL database. Some of the chart...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.