note 88412 added to function.session-id

From: Date: Thu, 22 Jan 2009 20:51:46 +0000
Subject: note 88412 added to function.session-id
Groups: php.notes 
Request: Send a blank email to php-notes+get-149676@lists.php.net to get a copy of this message
What does replacing the session id with session_id("something") actually do? It imply that doing so you would be able to mimic ASP style application variables with a 'shared' session, with something like the code below. However, each renaming the session does not appear to allow two seperate visitors to share the same session. Why not? Why else would one use this feature? <?php function test() { if (!$_SESSION['session_count']) $_SESSION['session_count'] = 0; $_SESSION['session_count']++; $count = get_cache( 'count' ); print "pre application count: $count<br>"; if ( !$count ) $count = 0; $count++; print "session_id: " . session_id() . "<br>"; print "post application count: $count<br>"; print "session_count: " . $_SESSION['session_count'] . "<br>"; set_cache('count', $count); } function set_cache( $name, $value ) { $old_session = session_id(); print "old_session (set): $old_session<br>"; session_id("GlobalCache"); print "new_session (set): " . session_id() . "<br>"; $_SESSION[$name] = $value; session_id( $old_session ); } function get_cache( $name ) { $old_session = session_id(); print "old_session (get): $old_session<br>"; session_id("GlobalCache"); print "new_session (get): " . session_id() . "<br>"; $value = $_SESSION[$name]; session_id( $old_session ); return $value; } session_start(); test(); ?> ---- Server IP: 64.71.164.2 Probable Submitter: 67.177.214.28 ---- Manual Page -- http://www.php.net/manual/en/function.session-id.php Edit -- https://master.php.net/note/edit/88412 Del: integrated -- https://master.php.net/note/delete/88412/integrated Del: useless -- https://master.php.net/note/delete/88412/useless Del: bad code -- https://master.php.net/note/delete/88412/bad+code Del: spam -- https://master.php.net/note/delete/88412/spam Del: non-english -- https://master.php.net/note/delete/88412/non-english Del: in docs -- https://master.php.net/note/delete/88412/in+docs Del: other reasons-- https://master.php.net/note/delete/88412 Reject -- https://master.php.net/note/reject/88412 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149676) next »