Re: session management with database: optimal parameters in php.ini



phicarre schreef:
I am developping one script for the "session management with database"
and I would like to know which parameters I must change in php.ini
according to these requirements:

- I am using the session_set_save_handler() function

good.

- I don't know if the client side uses or not the cookies

And you shouldn't care either. PHP will pass the sessionid to your functions you use in session_set_save_handler().


- Several clients can access in the same time to the web application

That is normal.
They all have a different sessionid, so that is fine.

- The web application shall be secured against classical attacks

Meaning what excactly?

I wrote a few db-sessionstorage routine, and here a some things I would have liked to know before. ;-)

1) Make sure you handle concurrency adequately in your routines.
If you finish the sessionhandling in the db, make a simple testpage to test concurrency:
a) Make a htmlpage with 20 frames.
b) Put in every frames testdb.php
c) testdb.php does something like this:
<?php
// your initstuff
if (isset($_SESSION["count"])){
$_SESSION["count"] = $_SESSION["count"] + 1;
} else {
$_SESSION["count"] = 1;
}
echo $_SESSION["count"];
?>

Now go to that framed page in your browser: The result would be a htmlpage with 20 frames that all hold different numbers (not necessarely all in order.)

2) Make sure you protect yourself against SQL-inject attacks.
Mind that the sessionid comes from the client, thus it can be tampered with. It might contain:
1'); DELETE FROM tblusers;

which you don't want to use in your query:
SELECT sessiondata FROM tblusers where (sessionid=$sessionid);

So normal paranoia applies here.

3) If you need inspiration:
a) ADODB (a database abstractionlayer) has a build-in sessionmanagement module for database, written in PHP.
http://www.phplens.com/adodb

4) If you use Postgres (which is a great database), you might have a look at:
http://nl.php.net/manual/en/book.session-pgsql.php

Good luck!

Regards,
Erwin Moller


--
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
.



Relevant Pages

  • Re: session management with database: optimal parameters in php.ini
    ... On 3 mar, 19:00, Erwin Moller ... They all have a different sessionid, ... Make a htmlpage with 20 frames. ... ADODB (a database abstractionlayer) has a build-in sessionmanagement ...
    (alt.php)
  • RE: [PHP] PHP Template Trouble
    ... No frames, no duplicated code. ... Subject: [PHP] PHP Template Trouble ... The sites are exactly the same except for the database, ...
    (php.general)
  • Re: Sessions , sql injection, misc attack defense
    ... Upto now my use of php has been personal, if someone hacked my site i would look at what they did and work around it. ... Now I decided to spend what time I can on a project I hope will become of some use to other people, I am concerned about attacks. ... session hijacking and sql injection. ... since the man-in-the-middle can still see the new sessionid in the response from the server. ...
    (comp.lang.php)
  • Re: Sessions , sql injection, misc attack defense
    ... Upto now my use of php has been personal, if someone hacked my site i would look at what they did and work around it. ... Now I decided to spend what time I can on a project I hope will become of some use to other people, I am concerned about attacks. ... session hijacking and sql injection. ... since the man-in-the-middle can still see the new sessionid in the response from the server. ...
    (comp.lang.php)
  • Re: Sessions , sql injection, misc attack defense
    ... Upto now my use of php has been personal, if someone hacked my site i would look at what they did and work around it. ... Now I decided to spend what time I can on a project I hope will become of some use to other people, I am concerned about attacks. ... session hijacking and sql injection. ... since the man-in-the-middle can still see the new sessionid in the response from the server. ...
    (comp.lang.php)