From 5514a3e5825cb9ef9060de8b474634fa3427a873 Mon Sep 17 00:00:00 2001 From: "Mark L. Woodward" Date: Sun, 23 Dec 2001 19:58:00 +0000 Subject: [PATCH] A php script which shows how to use msession with PHP sessions --- ext/msession/msession-test.php | 125 +++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 ext/msession/msession-test.php diff --git a/ext/msession/msession-test.php b/ext/msession/msession-test.php new file mode 100644 index 0000000000..e591fcca70 --- /dev/null +++ b/ext/msession/msession-test.php @@ -0,0 +1,125 @@ +\n"; + echo "Set Variable: " . msession_set($sid, 'name1','test1') ."

\n"; + echo "Set Variable: " . msession_set($sid, 'name2','test2') ."

\n"; + echo "Set Variable: " . msession_set($sid, 'name3','test3') ."

\n"; + echo "Set Variable: " . msession_set($sid, 'name4','test4') ."

\n"; + echo "Set Variable: " . msession_set($sid, 'name5','test5') ."

\n"; + echo "Set Variable: " . msession_set($sid, 'name6','test6') ."

\n"; + echo "Set Variable: " . msession_set($sid, 'name7','test7') ."

\n"; + } + else // All at once in an array + { + $setarray = array(); + $setarray['time']=time(); + $setarray['name1'] = 'test1'; + $setarray['name2'] = 'test2'; + $setarray['name3'] = 'test3'; + $setarray['name4'] = 'test4'; + $setarray['name5'] = 'test5'; + $setarray['name6'] = 'test6'; + $setarray['name7'] = 'test7'; + msession_set_array($sid, $setarray); + } +} +else +{ + $sid = $HTTP_COOKIE_VARS["PHPSESSID"]; +} + +#This makes a link between the variable $count and the +# session variable "count" +session_register("count"); + +$count ++; + +# Output some information. +echo "sid: " . $sid . "
\n"; +echo "Session Count: " . $count . "
\n"; + +# Use msession_randstr() to produce a random string. +# A valid string of n characters of jibberish is returned. +echo "Random String: " . msession_randstr(32) . "
\n"; + +# This is a thread safe increment, unlike PHP's session, many web servers +# can be updating this variable and collisions are managed. +# (for this to work, older versions of msessiond must be started with "-g globals" +# newer versions create it by default) +echo "Global Count: " . msession_inc(globals, "counter") . "
\n"; + +# This gets a count of active sessions. +echo "Total active sessions: " . msession_count() . "
\n"; + +# This gets all the variables for a user in an associative array. +$varray = msession_get_array($sid); + +if(!$varray) + echo "Get variable array: Failed
\n"; + +# Display all the user's variables +$arraykeys = array_keys($varray); +for($i=0; $arraykeys[$i]; $i++) + echo "Key: " . $arraykeys[ $i ] ." = " .$varray[$arraykeys[$i]] ."
\n"; + + +# Find a list of all sessions with same name/value pair +$array = msession_find('name1', 'test1'); + +#display the sessions +for($i=0; $array[$i]; $i++) + echo "Similar Sessions: " . $i . " " . $array[$i] . "
\n"; + +# Find all the sessions which have the variable "time" set. +$vararray = msession_listvar('time'); + +$arraykeys = array_keys($vararray); + +for($i=0; $arraykeys[$i]; $i++) + echo "Key: " . $arraykeys[ $i ] ." = " .$vararray[$arraykeys[$i]] ."
\n"; + +# msession can support a personality plugin, this is an escape call directly +# into the plugin's REQ_ESCAPE function. +echo "Call the plugin: " . msession_plugin($sid, 3, "test"). "
\n"; + +# msession also supprts function-only plugins. this is a call into the demo +# plugin (funct.so) which returns the uptime of the msessiond process. +echo "Call the function: " . msession_call('fntest', "1","2", "3", "4") ."
\n"; + +#List ALL sessions on the system +$sarray = msession_list(); + +for($i=0; $sarray[$i]; $i++) + echo "Sessions: " . $i . " " . $sarray[$i] . "
\n"; + +?> + -- 2.50.1