Re: Handling sessions through cookies, is it safe?



On or about 7/16/2006 8:55 PM, it came to pass that s a n j a y wrote:
romayankin@xxxxxxxxx wrote:
I need to limit the session time for a particular user who is working
on my site. I'd also like to extend the session time each time user
performs some action (moves from one page to another). I've written the
following code to accomplish this task

/* Extending session */
if(isset($_COOKIE['username'])) {
setcookie ("username", $_POST['username'], time()+3600);
}

Variable $_COOKIE['username'] right after the authorization is
completed.
The problem is that I don't think this is a safe way to handle
sessions. Perhaps I should use $_SESSION global array to store the
username of the logged user?


In my opinion, all you should store in a cookie is session-id. Everything else, you store on server in either global session veriable or in a database.
Agreed.
Set a session variable with php time() and do your own timeout.

if (isset($_SESSION['$Server_time']) && (time() - $_SESSION['$Server_time']) > 600)
$_SESSION = array(); //break this session and restart when over 10 minutes
$_SESSION['$Server_time'] = time(); //time in seconds
.



Relevant Pages

  • Re: Storing a datatable (or arraylist )on ASP.NET Session
    ... Perhaps your ArrayList store smth which can't be casted to object. ... If exactly that code u shown didn't work (emply arraylists) that I recomment to re-register asp.net 2.0 calling aspnet_regiis,exe - i ... Team blog: http://devkids.blogspot.com/ ... b> session variables is stored on web server's local sql database. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: LISP for web
    ... >>Ideas on how to store this information centrally for all of the app ... > ucw's form handling code (to make sure session ids are always ... > can deal with hardware failures an the app servers but this ...
    (comp.lang.lisp)
  • Re: Problem with asp.net app only allowing 1 user at a time
    ... from the client to the server), Application (an object that can store ... Now in your case you are reading and writing everything to the database, ... there is the Session object. ... To retrieve this you would do something like: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: LISP for web
    ... > Ideas on how to store this information centrally for all of the app ... the risk of losing data and sessions if one of the machines goes ... ucw's form handling code (to make sure session ids are always ...
    (comp.lang.lisp)
  • Re: Caching often-used SQL queries
    ... The problem is that neither one of those are user (session) specific. ... need to enable sessions and store the data in the session context. ... Second - you'd be caching so much data that it would ... And if you tune your database server you'll spend much more time processing ...
    (microsoft.public.dotnet.framework.performance)