if ( isset ( $_COOKIE [ "vegetable" ])){ echo " p Hello again, you have chosen: " . $_COOKIE [ "vegetable" ]. ". /p } else { echo " p Hello you. This may be your first visit. /p }
html head title Storing an array with a session /title /head body h1 Product Choice Page /h1 php if ( isset ( $_POST [ "form_products" ])){ if (! empty ( $_SESSION [ "products" ])){ $products = array_unique ( array_merge ( unserialize ( $_SESSION [ "products" ]), $_POST [ "form_produces" ])); } else { $_SESSION [ "products" ] = serialize ( $_POST [ "form_products" ]); } echo " p Your products have been registered! /p }
form method = "POST" action = " php echo $_SERVER [ "PHP_SELF" ]; " p strong Select some products: /strong br select name = "form_product[]" multiple = "multiple" size = "3" option value = "Sonic Screwdriver" Sonic Screwdriver /option option value = "Hal 2000" Hal 2000 /option option value = "Tardis" Tardis /option option value = "ORAC" ORAC /option option value = "Transporter bracelet" Transporter bracelet /option /select p input type = "submit" value = "choose" / /p /form p a href = "session1.php" go to content page /a /p /body /html
session1.php: 复制代码 代码如下: php /* * Created on 2011-1-19 * * To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code Templates */ session_start ();
html head title Accessing session variables /title /head body h1 Content Page /h1 php if ( isset ( $_SESSION [ "products" ])){ echo " strong Your cart: /strong ol foreach ( unserialize ( $_SESSION [ "products" ]) as $p ){ echo " li " . $p . " /li } echo " /ol }
p a href = "arraysession.php" return to product choice page /a /p /body /html 6.在查询字符串中传递会话 ID7.销毁会话和重置变量8.在一个带有注册用户的环境中使用会话希望本文所述对大家的php程序设计有所帮助。PHP教程