note 21748 added to ref.session

From: Date: Sat, 25 May 2002 06:01:50 +0000
Subject: note 21748 added to ref.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-31019@lists.php.net to get a copy of this message
I wrote a tiny "shopping-cart" code when I was learning PHP sessions. (Use ++ instead of =1 to allow more than one product of a kind in the cart). <?php session_start(); // - Add if( isset( $_GET['ADD'] ) ) { $_SESSION['aBasket'][$_GET['ID']] = 1; } // - Remove if( isset( $_GET['DEL'] ) ) { unset($_SESSION['aBasket'][$_GET['ID']]); } // - Remove All if( isset( $_GET['EMP'] ) ) { unset($_SESSION['aBasket']); } // - Show if( isset( $_SESSION['aBasket'] ) ) { foreach ( $_SESSION['aBasket'] as $key=>$val ) { echo "$key "; } } ?> <form> Product: <input type="text" name="ID"> <input type="submit" name="ADD" value="Add"> <input type="submit" name="DEL" value="Del"> <input type="submit" name="EMP" value="Empty"> </form> Gregory http://tiv.net/ -- http://www.php.net/manual/en/ref.session.php http://master.php.net/manage/user-notes.php?action=edit+21748 http://master.php.net/manage/user-notes.php?action=delete+21748 http://master.php.net/manage/user-notes.php?action=reject+21748

« previous php.notes (#31019) next »