Re: session_name("CCLTrolley")

From: Date: Mon, 03 Oct 2005 05:50:38 +0000
Subject: Re: session_name("CCLTrolley")
References: 1 2  Groups: php.general php.general 
Request: Send a blank email to php-general+get-223551@lists.php.net to get a copy of this message
This is what you recommended.
Is there a reason you're using a comma delimited string? I would recommend using an array instead: <?php session_name( 'CCLTrolley' ); session_start(); // Initialize the trolley. if( !isset( $_SESSION['TrolleyContents'] ) ) { $_SESSION['TrolleyContents'] = array(); } // Add new entry. if( isset( $_POST['AddToTrolley'] ) ) { $_SESSION['TrolleyContents'][$_POST['AddToTrolley']] = $_POST['AddToTrolley'] } echo implode( ',', $_SESSION['TrolleyContents'] ); phpinfo(); ?>
This is what I implemented? Where did I go wrong? John <?php session_name( 'CCLTrolley' ); session_start(); // Initialize the trolley. if( !isset( $_SESSION['TrolleyContents'] ) ) { $_SESSION['TrolleyContents'] = array(); } if("add" == $_POST['ShopAction']) { // Add new entry: if( isset( $_POST['RNum'] ) ) {
       $_SESSION['TrolleyContents'][$_POST['RNum']] = $_POST['RNum'];
} echo implode( ',', $_SESSION['TrolleyContents'] ); }else{ //Delete an entry: if( isset( $_SESSION['TrolleyContents'][$_POST['RNum']] ) ) {
   #    $_SESSION['TrolleyContents'][$_POST['RNum']] -= 1;
   #    if( $_SESSION['TrolleyContents'][$_POST['RNum']] <= 0 )
   #    {
           unset( $_SESSION['TrolleyContents'][$_POST['RNum']] );
   #    }
} } print_r( $_SESSION ); #phpinfo(); ?>

« previous php.general (#223551) next »