|
użytkowników online: 65
|
OPINIE UŻYTKOWNIKÓW
|
Na początku, kiedy zobaczyłem, że ktoś chce jakiejś opłaty za pomoc w tworzeniu stron ryknąłem śmiechem - potem przyszły problemy... i zaryzykowałem. Druga rzecz to: nie chciałem "kopiować". Ale prawda jest taka: są lepsi, bardziej doświadczeni i... czasem trzeba poprosić o pomoc, a jak poświęca się na to trzecią cześć życia, to nic dziwnego, że nie chce się swoich "sekretów" zdradzać za darmo. Skorzystałem z "algorytmy.pl" i naprawdę jestem z tego w 100% zadowolony, polecam - dla zawodowców (co się uczą) i amatorów (można skorzystać z gotowego rozwiązania).
Tomasz Czypicki
Cybernoxa
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
Rozdział 35. Ciasteczka (cookies)
PHP obsługuje ciasteczka HTTP (cookies). Jest to
mechanizm służący do przechowywania danych w przeglądarce i
w ten sposób śledzenia lub identyfikowania powracających użytkowników.
Można je ustawiać używając funkcji setcookie().
Ciasteczka stanowią część nagłówka HTTP, więc funkcja
setcookie() musi być wywoływana zanim jakiekolwiek dane
zostaną wysłane do przeglądarki. Występuje tu to samo ograniczenie,
co w przypadku header(). Możesz skorzystać z
funkcji buforujących,
aby opóźnić wysłanie danych do czasu, gdy zdecydujesz o wysłaniu ciasteczek
lub dodatkowych nagłówków.
Każde ciasteczko wysłane do ciebie od klienta, będzie automatycznie
przekształcone w zmienną PHP, podobnie, jak przy użyciu metod POST i GET,
zależnie od ustawienia dyrektyw konfiguracyjnych
register_globals i variables_order.
Jeśli chcesz przypisać wiele wartości do pojedynczego ciasteczka, po prostu
dodaj [] do nazwy ciasteczka.
W PHP 4.1.0 i późniejszych, tworzona jest globalna tablica
$_COOKIE, przechowująca wszystkie ciasteczka nadesłane
przez klienta. We wcześniejszych wersjach PHP, tworzona jest tablica
$HTTP_COOKIE_VARS, jeśli ustawiona została dyrektywa
konfiguracyjna track_vars. (To jest ustawione zawsze od PHP 4.0.3.)
Po więcej informacji, włącznie z uwagami o błędach przeglądarek, sięgnij do
opisu funkcji setcookie() i setrawcookie().
User Contributed Notesbmorency at jbmlogic dot com
07-Oct-2005 02:14
In response to the solution posted in the comment below, there are some practical issues with this solution that must be kept in mind and handled by your code. I developed an application using a similar "use-it-once" key to manage sessions and it worked great but we got some complaints about legitimate users getting logged out without reasons. Turns out the problem was not tentative highjacking, it was either:
A- Users double click on links or make 2 clicks very fast. The same key is sent for the 2 clicks because the new key from the first click didn't get to the browser on time for the second one but the session on the server did trash the key for the new one. Thus, the second click causes a termination of the session. (install the LiveHttpHeaders extension on firefox and look at the headers sent when you click twice very fast, you'll see the same cookie sent on both and the new cookie getting back from the server too late).
B- For any given reason, the server experiences a slow down and the response with the new key (which has replaced the old one on the server) is not returned to the browser fast enough. The user gets tired of waiting and clicks somewhere else. He gets logged out because this second click send the old key which won't match the one you have on your server.
Our solution was to set up a grace period where the old key was still valid (the current key and the previous key were both kept at all times, we used 15 seconds as a grace period where the old key could still be used). This has the drawback of increasing the window of time for a person to highjack the session but if you tie the validity of the old key to an IP address and/or user agent string, you still get pretty good session security with very very few undesired session termination.
mega-squall at caramail dot com
23-Feb-2005 10:04
I found a solution for protecting session ID without tying them to client's IP. Each session ID gives access for only ONE querry. On the next querry, another session ID is generated and stored. If somebody hacks the cookie (or the session ID), the first one of the user and the pirate that will use the cookie will get the second disconnected, because the session ID has been used.
If the user gets disconnected, he will reconnect : as my policy is not to have more than one session ID for each user (sessions entries have a UNIQUE key on the collomn in which is stored user login), every entries for that user gets wiped, a new session ID is generated and stored on users dirve : the pirate gets disconnected. This lets the pirate usually just a few seconds to act. The slower visitors are browsing, the longer is the time pirates get for hacking. Also, if users forget to explicitly end their sessions .... some of my users set timeout longer than 20 minutes !
IMPORTANT NOTE : This disables the ability of using the back button if you send the session ID via POST or GET.
James Olsen
22-Jan-2005 05:14
Tying the session to the IP of the user is not a good idea. Some users, notably AOL users, are behind a rotating proxy which means their hits to the server will actually be coming from different IP addresses over the duration of their visit. Trying the session to the IP will not work properly for those users.
myfirstname at braincell dot cx
24-Sep-2003 05:47
[Editor's note: Wilson's comment has been deleted since it didn't contain much useful information, but this note is preserved although its reference is lost]
Just a general comment on Wilton's code snippet: It's generally considered very bad practice to store usernames and/or passwords in cookies, whether or not they're obsfucated. Many spyware programs make a point of stealing cookie contents.
A much better solution would be to either use the PHP built in session handler or create something similar using your own cookie-based session ID. This session ID could be tied to the source IP address or can be timed out as required but since the ID can be expired separately from the authentication criteria the authentication itself is not compromised.
Stuart Livings
|