note 88412 deleted from function.session-id by danbrown
| From: | danbrown@php.net | Date: | Thu, 22 Jan 2009 22:45:55 +0000 |
| Subject: | note 88412 deleted from function.session-id by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149677@lists.php.net to get a copy of this message | ||
Note Submitter: Tristan Havelick
----
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();
?>