You are here: Re: [PHP] session_name("CCLTrolley") « PHP « IT news, forums, messages
Re: [PHP] session_name("CCLTrolley")

Posted by John Taylor-Johnston on 10/03/05 08:50

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();
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация