Forum Moderators: coopster

Message Too Old, No Replies

a liitle help on sessions?

         

ktsirig

11:11 pm on Mar 2, 2006 (gmt 0)

10+ Year Member



Hi,
I am trying ac ouple of days now to learn some things on SESSIONS,but I think I am not getting it very clearly.
I have a PHP page tha contains a form.
Users enter data in the form, which are then written in a file (the file is created at the time a user enters some data)
The file is then given as an input to an external program
The external program runs and gives some results which are then stored in another file (that is created when the external program finishes)
What I want to do is to somehow create these files and, when the user exits from the browser, then both files that refer to this user, will be deleted.
Most guys in the forums suggested I use sessions, and go like this :
1) User "nick" enters data in the form
2) Temporary file $nick_session_id.FILE is created and passed on to the external program as input
3) The external program saves the results in another temporary file, say $nick_session_id.RESULTS
4) When nick sees anything he wants to see in his browser, concerning the results etc and exits, then
both $nick_session_id.FILE & $nick_session_id.RESULTS will be deleted automatically (so the administrator doesn't have to erase files from the hard disk
all the time).

Pls note that I am not describing any kind of user authentication system, ie there is no log in/out in my page.
Also, the users, as described above,cannot write anything to the input file once they write their data in the form and push "Submit".
Of course, they cannot write anything to the results file as well, as this file contains the results given by the external program.

i apologize for the length of my message but I wanted to make it as clear as possible...
Many thanks!

coopster

2:16 am on Mar 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



One note I will mention is that although you have an external program in between that does not always mean that a user might not be writing to your external file. We always, always have to be careful of user-supplied data.

Sessions are a way to maintain state between you (the server) and the user (user's browser). Each request from the browser to you is processed, served, and the disconnect happens. A session allows us to keep some of that information stored until the next visit. That's the kicker though ... if the user doesn't visit again, or closes their browser, you have no idea. So what happens with all that information we were keeping around? Garbage collection. That's the term for it. PHP has some built in mechanisms to rifle through those session files and clean house once in awhile.

If you wanted to look through that data first, you are going to have to write your own garbage collection routine. I would also recommend writing some kind of timestamp into your database table so you can do some garbage collection on that as well.