|
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]
session_id (PHP 4, PHP 5) session_id -- Pobierz i/lub ustaw identyfikator bieżącej sesji Opisstring session_id ( [string id] )
session_id() zwraca identyfikator sesji dla bieżącej
sesji.
Jeśli podany został parametr id, zostanie
on użyty do zmiany identyfikatora bieżącej sesji. Przy takim użyciu
session_id() musi być wywołane przed
session_start(). Zależnie od funkcji obsługi sesji,
nie wszystkie znaki są dozwolone wewnątrz identyfikatora sesji. Na
przykład, funkcje obsługi sesji oparte na plikach pozwalają tylko na
znaki z przedziału a-z, A-Z i 0-9.
Notatka:
Używając ciasteczek sesyjnych, podanie parametru
id funkcji session_id()
spowoduje wysłanie nowego ciasteczka przy wywołaniu funkcji
session_start(), niezależnie od tego czy bieżący
identyfikator sesji jest identyczny z tym, który ma być ustawiony.
Do pobrania nazwy i identyfikatora bieżącej sesji moża być użyta także
stała SID, która zawiera string odpowiedni do
dodawania go do URLi. Zauważ, że SID jest
zdefiniowane tylko jeśli klient nie wysłał prawidłowego ciasteczka.
Przeczytaj także rozdział Obsługa sesji
Patrz także: session_start(),
session_set_save_handler() i session.save_handler.
User Contributed Notesjwhatcher at hotmail dot com
07-Jul-2005 09:21
Killing the session_id when using cookies to store the session_id. Useful when needing to recreate a user with different session information during an open session.
unset($_COOKIE[session_name()]);
session_start();
jpjounier at hotmail dot com
23-Jun-2005 01:28
About the note from Cybertinus :
The following test doesn't work, the code following is always executed :
if(!session_id())
{
// Always executed even if there's already an opened session
}
session_id() returns an empty string if there is no current session, so to test if a session already exists, it's better to write this :
if(session_id() == "")
{
start_session();
}
else
{
// Anything you want
}
cbarnes at bfinity dot net
10-May-2005 03:44
Note that Firefox and Mozilla use the same process for launching new windows or tabs, they will pick up the same session id as the previous windows until the parent process dies or is closed. This may cause undesired results if the session id is stored in a db and checked, a solution is to check at the new entry point (new tab or window if the user went back to the index page) for an existing session. If a session id exists and a new one is required use something like:
$ses_id = session_id();
$bsid_exists = false;
$bsid_exists = check_session_id_from_db($ses_id);
if ($bsid_exists){
//This is a reentry and the session already exists
// create a new session ID and start a new
session_regenerate_id();
$ses_id = session_id();
}
jeff_zamrzla
11-Feb-2005 12:03
Try this code snippet, from a book by a security expert who says this is more secure to place on every page:
session_start();
$_SESSION['name'] = "YourSession";
if (!isset($_SESSION['initiated']))
{
session_regenerate_id();
$_SESSION['initiated'] = true;
}
karlhaines at comcast dot net
31-Oct-2003 02:05
Rewriting URL's is not suggested for obvious security issues. Please be careful with register_globals when using sessions! Check that all information you recieve from a user is valid before accepting it!
Andi, info at pragmaMx dot org
16-Jan-2003 10:13
you can also add the iframe tag:
ini_set("url_rewriter.tags", "a=href,area=href,frame=src,iframe=src,input=src,form=fakeentry");
|