~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to ext/msession/msession-test.php

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?
 
2
#       msession-test.php
 
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
 
7
#       extension.
 
8
#
 
9
 
10
#
 
11
 
 
12
# Start the session system, this will connect to msession
 
13
# as configured in PHP.INI.
 
14
#
 
15
# Start sessions, this will set a cookie.
 
16
session_start();
 
17
 
 
18
# Now, optional, use msession_uniq() to create a guarenteed
 
19
# uniq session name.
 
20
 
21
if(!$HTTP_COOKIE_VARS["PHPSESSID"])
 
22
{
 
23
        # Use uniq to create the session. This is guarenteed to be
 
24
        # uniq in the server.
 
25
        $sid = msession_uniq(32);
 
26
        setcookie ("PHPSESSID", $sid);
 
27
        session_id($sid);
 
28
        $HTTP_COOKIE_VARS["PHPSESSID"] = $sid;
 
29
        # New session, set some variables
 
30
        if(0) // One at a time
 
31
        {
 
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";
 
40
        }
 
41
        else // All at once in an array
 
42
        {
 
43
                $setarray = 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);
 
53
        }
 
54
}
 
55
else
 
56
{
 
57
        $sid = $HTTP_COOKIE_VARS["PHPSESSID"];
 
58
}
 
59
 
 
60
#This makes a link between the variable $count and the
 
61
# session variable "count"
 
62
session_register("count");
 
63
 
 
64
$count ++;
 
65
 
 
66
# Output some information.
 
67
echo "sid: " . $sid . "<br>\n";
 
68
echo "Session Count: " . $count . "<br>\n";
 
69
 
 
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";
 
73
 
 
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";
 
79
 
 
80
# This gets a count of active sessions.
 
81
echo "Total active sessions: " . msession_count() . "<br>\n";
 
82
 
 
83
# This gets all the variables for a user in an associative array.
 
84
$varray = msession_get_array($sid);
 
85
 
 
86
if(!$varray)
 
87
        echo "Get variable array: Failed<br>\n";
 
88
 
 
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";
 
93
 
 
94
        
 
95
# Find a list of all sessions with same name/value pair
 
96
$array = msession_find('name1', 'test1');
 
97
 
 
98
#display the sessions
 
99
for($i=0; $array[$i]; $i++)
 
100
        echo "Similar Sessions: " . $i . " " . $array[$i] . "<br>\n";
 
101
 
 
102
# Find all the sessions which have the variable "time" set.
 
103
$vararray = msession_listvar('time');
 
104
 
 
105
$arraykeys = array_keys($vararray);
 
106
 
 
107
for($i=0; $arraykeys[$i]; $i++)
 
108
        echo "Key: " . $arraykeys[ $i ] ." = " .$vararray[$arraykeys[$i]] ."<br>\n";
 
109
 
 
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";
 
113
 
 
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"; 
 
117
 
 
118
#List ALL sessions on the system
 
119
$sarray = msession_list();
 
120
 
 
121
for($i=0; $sarray[$i]; $i++)
 
122
        echo "Sessions: " . $i . " " . $sarray[$i] . "<br>\n";
 
123
 
 
124
?>
 
125