/home/wpollock1/public_html/PHP/Session.php
1: <?php require_once "prolog.php" ?>
2: <!--
3: The above sets the content type and generates the following prolog,
4: if the browser accepts XHTML (extra space added to prevent parsing):
5:
6: < ?xml version="1.0" encoding="utf-8"?>
7: < ?xml-stylesheet href="#internalStyle" type="text/css"?>
8: < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
9: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
10: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
11: -->
12:
13: <head>
14: <meta http-equiv="Content-Type"
15: content="application/xhtml+xml; charset=utf-8" />
16: <meta http-equiv="Vary" content="Content-language" />
17:
18: <title> PHP Session test </title>
19:
20: <style type="text/css" id="internalStyle">
21: <![CDATA[
22: body { background-color: cyan; }
23: h1 { text-align: center; }
24: label.error { color: red; }
25: #name { float: left; padding-right: 5em; }
26: #medInfo { float: left; padding-right: 5em; }
27: #submit { clear: both; padding: .25em; }
28: #sess_open, #sess_close { background-color: gray; }
29: ]]>
30: </style>
31: </head>
32:
33: <body>
34: <div>
35: <pre id="sess_open">
36: <?php
37: function sess_open ( $sess_path, $sess_name )
38: {
39: print "Session Opened: Path=\"$sess_path\", Name=\"$sess_name\"\n";
40: return true;
41: }
42:
43: function sess_close ()
44: {
45: print "Session closed.\n";
46: return true;
47: }
48:
49: function sess_read ( $sess_id )
50: {
51: print "Session read: ID=\"$sess_id\"\n";
52: return '';
53: }
54:
55: function sess_write ( $sess_id, $data )
56: {
57: print "Session written: ID=\"$sess_id\"\n Data=\"$data\"\n";
58: return true;
59: }
60:
61: function sess_destroy ( $sess_id )
62: {
63: print "Session destroyed: ID=\"$sess_id\"\n";
64: return true;
65: }
66:
67: function sess_gc ( $sess_max_lifetime )
68: {
69: print "Session garbage collected: "
70: . "Max Lifetime=\"$sess_max_lifetime\"\n";
71: return true;
72: }
73:
74: session_set_save_handler( "sess_open", "sess_close", "sess_read",
75: "sess_write", "sess_destroy", "sess_gc" );
76:
77: session_start();
78: if (empty($_SESSION['count'])) {
79: $_SESSION['count'] = 1;
80: } else {
81: $_SESSION['count']++;
82: }
83: print "You have visited this site " . $_SESSION['count'] . " times!";
84:
85: $_SESSION['foo'] = 'bar';
86: $_SESSION['bar'] = 'baz';
87: $scriptName = preg_replace( '/.*[\\\\\/]([^\\\\\/]+)$/', '$1', __FILE__ );
88: ?>
89: </pre>
90:
91: <h1> Form Demo with LABEL, FIELDSET Elements </h1>
92:
93: <form action="<?php print $scriptName; ?>" method="post">
94:
95: <fieldset id="personalInfo">
96: <legend> Personal Information </legend>
97:
98: <div id="name">
99: <p>
100: <label for="fname">
101: First Name:
102: <input type="text" id="fname" tabindex="20" />
103: </label>
104: </p>
105:
106: <p>
107: <label for="lname">
108: Last Name:
109: <input type="text" id="lname" tabindex="25" />
110: </label>
111: </p>
112: </div>
113:
114: <div id="personalData">
115: <p>
116: <label for="age">
117: Age: <select id="age" tabindex="30">
118: <option value="None">Select</option>
119: <option value="Under 18">Under 18</option>
120: <option value="19-21">19 to 21</option>
121: <option value="21-33">21 to 33</option>
122: <option value="34-45">34 to 45</option>
123: <option value="46-65">46 to 65</option>
124: <option value="Over 65">Over 65</option>
125: </select>
126: </label>
127: </p>
128:
129: <p>
130: <label>
131: Material Status:
132: <input type="radio" name="maritalStatus" value="single"
133: tabindex="31" /> Single
134: <input type="radio" name="maritalStatus" value="married"
135: tabindex="32" /> Maried
136: </label>
137: </p>
138: </div>
139: </fieldset>
140:
141: <fieldset id="medInfo">
142: <legend> Current Medication </legend>
143:
144: <p>
145: <label>
146: Are you currently taking any medication?
147: <input name="current_meds" type="radio" value="Yes"
148: tabindex="35" />Yes
149: <input name="current_meds" type="radio" value="No"
150: tabindex="36" />No
151: </label>
152: </p>
153:
154: <p>
155: <label for="meds_list">
156: If you are currently taking medication, please indicate
157: it in the space below:<br />
158: <textarea id="meds_list" rows="4" cols="40" tabindex="40"></textarea>
159: </label>
160: </p>
161: </fieldset>
162:
163: <fieldset id="sports">
164: <legend> Activities </legend>
165: <p>
166: <label>
167: <input type="checkbox" name="activities[]" value="baseball"
168: tabindex="51" /> Baseball
169: </label><br />
170: <label>
171: <input type="checkbox" name="activities[]" value="bowling"
172: tabindex="52" /> Bowling
173: </label><br />
174: <label>
175: <input type="checkbox" name="activities[]" value="running"
176: tabindex="53" /> Running/Jogging
177: </label><br />
178: <label>
179: <input type="checkbox" name="activities[]" value="tiddily-winks"
180: tabindex="54" /> Tiddily Winks
181: </label><br />
182: <label>
183: <input type="checkbox" name="activities[]" value="solitaire"
184: tabindex="55" /> Solitaire
185: </label><br />
186: </p>
187: </fieldset>
188:
189: <p id="submit">
190: <input type="submit" value="Submit" tabindex="60" />
191: </p>
192: </form>
193: </div>
194:
195: <div>
196: <pre id="sess_close">
197: <?php
198: session_write_close();
199: ?>
200: </pre>
201: </div>
202:
203: </body></html>