Update of /cvsroot/phplib/php-lib/pages
In directory usw-pr-cvs1:/tmp/cvs-serv2438/pages
Added Files:
ct_cookie.php3 ct_cookie_logout.php3 ct_cookie_user.php3
Log Message:
Add ct_cookie.inc, a container class that stores data in cookies.
Also, a documentation page, sample pages using the class for both
sess and user and an ARC4 implementation for encryption.
The basis for this class was posted to the support mailing list by
Ing. Alejandro Vzquez C. <al...@in...> in August 2000.
--- NEW FILE: ct_cookie.php3 ---
<?php
// include("prepend.php3");
# We are using the following features on this page:
# sess for session variables
page_open(array("sess" => "Example_Cookie_Session"));
# s is a per session variable
if (!isset($s)) { $s=0; };
$sess->register("s");
# sess_value is also a per session variable
if (!isset($sess_value)) { $sess_value=0; };
$sess->register("sess_value");
?>
<html>
<body bgcolor="#ffffff">
<a href="<?php $sess->pself_url()?>">Reload</a> this page to see the counters increment.<br>
<a href="<?php $sess->purl("ct_cookie_user.php3")?>">Load</a> a more complex example (login as kris, password test).<br>
<a href="<?php $sess->purl("ct_cookie_logout.php3") ?>">Logout</a> and delete your authentication information.<br>
<p>
This is a simple example of an alternative storage container. In this case
the per session data and per user data is stored in client-side cookies.
No server-side storage is needed, but cookies *must* be enabled in the
user's browser. In practice this is not a very useful way of maintaining
state, but it is a nice example.
</p>
<?php
// Demonstration of per session data: We are incrementing a scalar, $s.
printf("<h1>Per Session Data: %s</h1>\n", ++$s);
?>
<p>
Per Session Data is referenced by session id. The session id is propagated
using a cookie stored in the users browser. The Per Session Data is stored
in other cookies by the user's browser.
</p>
<p>
Per Session Data is available only on pages using the feature
"sess" in their page_open() call.
</p>
<?php
if (isset($sess_action)) {
switch ($sess_action) {
case 'reset':
$sess_value = 0;
break;
case 'sub':
$sess_value--;
break;
case 'add':
$sess_value++;
break;
}
}
?>
<h1>Another Session variable: <?php echo $sess_value ?></h1>
<a href="<?php $sess->purl("$PHP_SELF?sess_action=add") ?>">Add</a><br>
<a href="<?php $sess->purl("$PHP_SELF?sess_action=sub") ?>">Subtract</a><br>
<a href="<?php $sess->purl("$PHP_SELF?sess_action=reset") ?>">Reset</a><br>
</body>
</html>
<?php
// Save data back to database.
page_close()
?>
<!-- $Id: ct_cookie.php3,v 1.1 2001/09/04 00:21:19 richardarcher Exp $ -->
--- NEW FILE: ct_cookie_logout.php3 ---
<?php
// include("prepend.php3");
# We are using the following features on this page:
# sess for session variables
# auth for user authentication (yes, you need to be logged in to log out :-)
page_open(array("sess" => "Example_Cookie_Session",
"auth" => "Example_Auth")
);
# s is a per session variable
if (!isset($s)) { $s=0; };
$sess->register("s");
# sess_value is also a per session variable
if (!isset($sess_value)) { $sess_value=0; };
$sess->register("sess_value");
?>
<html>
<body bgcolor="#ffffff">
<a href="<?php $sess->pself_url()?>">Reload</a> this page.<br>
<a href="<?php $sess->purl("ct_cookie.php3")?>">Return</a> to the simple example page.<br>
<a href="<?php $sess->purl("ct_cookie_user.php3")?>">Load</a> a more complex example (login as kris, password test).<br>
<a href="<?php $sess->purl("ct_cookie_logout.php3") ?>">Logout</a> and delete your authentication information.<br>
<p>
This is a simple example of an alternative storage container. In this case
the per session data and per user data is stored in client-side cookies.
No server-side storage is needed, but cookies *must* be enabled in the
user's browser. In practice this is not a very useful way of maintaining
state, but it is a nice example.
</p>
<h1>logout</h1>
You have been logged in as <b><?php print $auth->auth["uname"] ?></b> with
<b><?php print $auth->auth["perm"] ?></b> permission. Your authentication
was valid until <b><?php print date("d. M. Y, H:i:s", $auth->auth["exp"])
?></b>.<p>
<?php
$auth->logout();
?>
<p>
This is all over now. You have been logged out.
</p>
<p>
Per Session Data is still available -- it is just the current Auth
data that has been deleted. The Per User data still exists and will
be available next time the user logs in.
</p>
<?php
// Demonstration of per session data: We are incrementing a scalar, $s.
printf("<h1>Per Session Data: %s</h1>\n", ++$s);
?>
</body>
</html>
<?php
// Save data back to database.
page_close()
?>
<!-- $Id: ct_cookie_logout.php3,v 1.1 2001/09/04 00:21:19 richardarcher Exp $ -->
--- NEW FILE: ct_cookie_user.php3 ---
<?php
// include("prepend.php3");
# We are using the following features on this page:
# sess for session variables
# auth for login checks, also required for user variables
# perm for permission checks
# user for user variables
page_open(array("sess" => "Example_Cookie_Session",
"auth" => "Example_Auth",
"perm" => "Example_Perm",
"user" => "Example_Cookie_User")
);
# page access requires that the user is authenticated and has "admin" permission
$perm->check("admin");
# s is a per session variable
if (!isset($s)) { $s=0; };
$sess->register("s");
# sess_value is also a per session variable
if (!isset($sess_value)) { $sess_value=0; };
$sess->register("sess_value");
# u is a per user variable
if(!isset($u)) { $u=0; };
$user->register("u");
# user_value is also a per user variable
if (!isset($user_value)) { $user_value=0; };
$sess->register("user_value");
?>
<html>
<body bgcolor="#ffffff">
<a href="<?php $sess->pself_url()?>">Reload</a> this page to see the counters increment.<br>
<a href="<?php $sess->purl("ct_cookie.php3")?>">Return</a> to the simple example page.<br>
<a href="<?php $sess->purl("ct_cookie_logout.php3") ?>">Logout</a> and delete your authentication information.<br>
<p>
This is a simple example of an alternative storage container. In this case
the per session data and per user data is stored in client-side cookies.
No server-side storage is needed, but cookies *must* be enabled in the
user's browser. In practice this is not a very useful way of maintaining
state, but it is a nice example.
</p>
<?php
// Demonstration of per session data: We are incrementing a scalar, $s.
printf("<h1>Per Session Data: %s</h1>\n", ++$s);
?>
<p>
Per Session Data is referenced by session id. The session id is propagated
using a cookie stored in the users browser. The Per Session Data is stored
in other cookies by the user's browser.
</p>
<p>
Per Session Data is available only on pages using the feature
"sess" in their page_open() call.
</p>
<?php
if (isset($sess_action)) {
switch ($sess_action) {
case 'reset':
$sess_value = 0;
break;
case 'sub':
$sess_value--;
break;
case 'add':
$sess_value++;
break;
}
}
?>
<h1>Another Session variable: <?php echo $sess_value ?></h1>
<a href="<?php $sess->purl("$PHP_SELF?sess_action=add") ?>">Add</a><br>
<a href="<?php $sess->purl("$PHP_SELF?sess_action=sub") ?>">Subtract</a><br>
<a href="<?php $sess->purl("$PHP_SELF?sess_action=reset") ?>">Reset</a><br>
<?php
// Demonstration of per user data: We are incrementing a scalar, $u.
printf("<h1>Per User Data: %s</h1>\n", ++$u);
?>
<p>
Per User Data is referenced by user id. The user id is stored as a session
variable in each authenticated session. Once again, in this example the Per
User Data is being stored in cookies by the user's browser.
</p>
<p>
Per User Data is only available on authenticated pages (pages using the
feature "auth" in addition to the feature "sess"). It
is activated by using the feature "user".
</p>
<?php
if (isset($user_action)) {
switch ($user_action) {
case 'reset':
$user_value = 0;
break;
case 'sub':
$user_value--;
break;
case 'add':
$user_value++;
break;
}
}
?>
<h1>Another User variable: <?php echo $user_value ?></h1>
<a href="<?php $sess->purl("$PHP_SELF?user_action=add") ?>">Add</a><br>
<a href="<?php $sess->purl("$PHP_SELF?user_action=sub") ?>">Subtract</a><br>
<a href="<?php $sess->purl("$PHP_SELF?user_action=reset") ?>">Reset</a><br>
<h2>Some interesting variables</h2>
<?php
// Show how to access the session and the user id.
printf("Your session id is %s<br>\n", $sess->id);
printf("Your user id is %s<br>\n", $user->id);
printf("This should be the same as %s<br>\n", $auth->auth["uid"]);
printf("You have the permissions %s<br>\n", $auth->auth["perm"]);
?>
</body>
</html>
<?php
// Save data back to database.
page_close()
?>
<!-- $Id: ct_cookie_user.php3,v 1.1 2001/09/04 00:21:19 richardarcher Exp $ -->
|