|
home—lects—exams—hws
D2L—breeze (snow day)
From PHP Visual Quickstart Guide by Larry Ullman
Originally based on notes by Jack Davis (jcdavis@radford.edu)
We have looked at how php includes
Remember that sessions (and, cookies) span multiple windows/frames within the same browser.
Imagine:
Btw, I don't think that cookies (and hence sessions) get shared between different computers1, but it's conceivable that Chrome might allow sync'ing of cookies. Certainly, I personally synchronize my files between two different computers (which includes stored cookies).
This means that if you have javascript which stores info client-side in files, your application should be robust against that file seeming to “disappear” halfway through a session. (Really, you should be somewhat robust against this regardless.)
Gotcha:session_start() puts a write-lock on the session file, so any other process trying to access it will block. (In particular: that 'other process' might be yourself, via an included-file which is also doing asession_start() !) One possible workaround (and good practice regardless): As soon as you're done updating any persistent values to$_SESSION , callsession_commit . This writes and closes the data file, although it doesn't unset data in memory so you can still refer to$_SESSION . (Just remember that any later changes made to the array are no longer being committed, and because you've given up the lock others might be updating the file w/o you seeing any changes. You can apparently callsession_commit again later, though presumably if some other process is accessing the file it may block and then it will overwrite the other file's changes.)
IMPORTANT:
If your session allows access to any secure information
(for instance, once a user successfully types a password,
you set
But we don't create that cookie ourselves!
We'd just called
php_ini('session.cookie_secure',true) |
IT-AUTH -- source-code not released to students, since it enables students to create popular RU pages that authenticate and surreptitiously log each user's password.
The solution is clever: Your page has a form that submits to https://php.radford.edu/~it-auth/vsp09/login.php. Your form passes in two strings (via hidden inputs, presumably):
Don't tempt an honest man.
To be effective, you'd better use a cookie-name that can't be guessed —
in particular, if I use your site and then check my own cookies,
hopefully I won't be able to look at that cookie name/value and
guess what somebody else's cookie name/value is!
https://php.radford.edu/~it-auth/vsp09/tutorial.php
In fact, it's conceivable that
two different browsers might share cookies —
e.g. Firefox and Mozilla intentionally using the
same cookie directory.
So your server-side code shouldn't really care/notice
if the user manages to “migrate” a session
from one browser to another;
your server probably shouldn't store
(say) the browser-type in
Besides, in that example (browser-type), the correct solution happens to be checking the http header's User-Agent field.
↩home—lects—exams—hws
D2L—breeze (snow day)
©2012, Ian Barland, Radford University Last modified 2013.Apr.01 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |