3
# This is a test page for msession functions.
4
# most msession functions are used in this page with
5
# the exception of msession_get_data, and msession_set_data
6
# which are used implicitly with the PHP session
12
# Start the session system, this will connect to msession
13
# as configured in PHP.INI.
15
# Start sessions, this will set a cookie.
18
# Now, optional, use msession_uniq() to create a guarenteed
21
if(!$HTTP_COOKIE_VARS["PHPSESSID"])
23
# Use uniq to create the session. This is guarenteed to be
25
$sid = msession_uniq(32);
26
setcookie ("PHPSESSID", $sid);
28
$HTTP_COOKIE_VARS["PHPSESSID"] = $sid;
29
# New session, set some variables
30
if(0) // One at a time
32
echo "Set Variable: " . msession_set($sid, 'time',time()) ."<p>\n";
33
echo "Set Variable: " . msession_set($sid, 'name1','test1') ."<p>\n";
34
echo "Set Variable: " . msession_set($sid, 'name2','test2') ."<p>\n";
35
echo "Set Variable: " . msession_set($sid, 'name3','test3') ."<p>\n";
36
echo "Set Variable: " . msession_set($sid, 'name4','test4') ."<p>\n";
37
echo "Set Variable: " . msession_set($sid, 'name5','test5') ."<p>\n";
38
echo "Set Variable: " . msession_set($sid, 'name6','test6') ."<p>\n";
39
echo "Set Variable: " . msession_set($sid, 'name7','test7') ."<p>\n";
41
else // All at once in an array
44
$setarray['time']=time();
45
$setarray['name1'] = 'test1';
46
$setarray['name2'] = 'test2';
47
$setarray['name3'] = 'test3';
48
$setarray['name4'] = 'test4';
49
$setarray['name5'] = 'test5';
50
$setarray['name6'] = 'test6';
51
$setarray['name7'] = 'test7';
52
msession_set_array($sid, $setarray);
57
$sid = $HTTP_COOKIE_VARS["PHPSESSID"];
60
#This makes a link between the variable $count and the
61
# session variable "count"
62
session_register("count");
66
# Output some information.
67
echo "sid: " . $sid . "<br>\n";
68
echo "Session Count: " . $count . "<br>\n";
70
# Use msession_randstr() to produce a random string.
71
# A valid string of n characters of jibberish is returned.
72
echo "Random String: " . msession_randstr(32) . "<br>\n";
74
# This is a thread safe increment, unlike PHP's session, many web servers
75
# can be updating this variable and collisions are managed.
76
# (for this to work, older versions of msessiond must be started with "-g globals"
77
# newer versions create it by default)
78
echo "Global Count: " . msession_inc(globals, "counter") . "<br>\n";
80
# This gets a count of active sessions.
81
echo "Total active sessions: " . msession_count() . "<br>\n";
83
# This gets all the variables for a user in an associative array.
84
$varray = msession_get_array($sid);
87
echo "Get variable array: Failed<br>\n";
89
# Display all the user's variables
90
$arraykeys = array_keys($varray);
91
for($i=0; $arraykeys[$i]; $i++)
92
echo "Key: " . $arraykeys[ $i ] ." = " .$varray[$arraykeys[$i]] ."<br>\n";
95
# Find a list of all sessions with same name/value pair
96
$array = msession_find('name1', 'test1');
99
for($i=0; $array[$i]; $i++)
100
echo "Similar Sessions: " . $i . " " . $array[$i] . "<br>\n";
102
# Find all the sessions which have the variable "time" set.
103
$vararray = msession_listvar('time');
105
$arraykeys = array_keys($vararray);
107
for($i=0; $arraykeys[$i]; $i++)
108
echo "Key: " . $arraykeys[ $i ] ." = " .$vararray[$arraykeys[$i]] ."<br>\n";
110
# msession can support a personality plugin, this is an escape call directly
111
# into the plugin's REQ_ESCAPE function.
112
echo "Call the plugin: " . msession_plugin($sid, 3, "test"). "<br>\n";
114
# msession also supprts function-only plugins. this is a call into the demo
115
# plugin (funct.so) which returns the uptime of the msessiond process.
116
echo "Call the function: " . msession_call('fntest', "1","2", "3", "4") ."<br>\n";
118
#List ALL sessions on the system
119
$sarray = msession_list();
121
for($i=0; $sarray[$i]; $i++)
122
echo "Sessions: " . $i . " " . $sarray[$i] . "<br>\n";