Re: =sessions / J. Meloni Textbook=

From: Date: Thu, 20 Nov 2003 05:02:17 +0000
Subject: Re: =sessions / J. Meloni Textbook=
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-170385@lists.php.net to get a copy of this message
Additinally, upon looking at the session files in: C:/apache/tmp: I get from session file from script session_1a.php: products|s:23:"a:1:{i:0;s:6:"Tardis";}"; ................... However, looking at session file from script session_1.php: I get: products|s:2:"N;"; -- "Anthony Ritter" <tony@gonefishingguideservice.com> wrote in message news:20031120045245.37235.qmail@pb1.pair.com... > Sure. > > Here it is. > > There are three scripts. > > session_1.php: the original form script. > session_1a.php: a revised script with a conditional else. > session_2.php: the receiving script for the session array variable. > > Running script 1a and 2 works fine. > > However the original script 1 and 2 gives me a error when returning to the > contents page the first time - it then fills the contents starting with the > number 2 on subsequent page loads. > > as in: > 1. > 2. Hal 2000 > 3. Sonic Screwdriver > > Try it and see and let me know. > Thank you. > TR > ............................. > > > // this is the original script > // script session_1.php > > <?php > session_start(); > ?> > <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_products])); > } > $_SESSION[products] = serialize($products); > print "<p>Your products have been registered!</p>"; > } > ?> > <form method="POST" action="<?php $_SERVER[PHP_SELF] ?>"> > <P>Select some products:<br> > <select name="form_products[]" multiple size=3> > <option>Sonic Screwdriver</option> > <option>Hal 2000</option> > <option>Tardis</option> > <option>ORAC</option> > <option>Transporter bracelet</option> > </select> > <br><br> > <input type="submit" value="choose"> > </form> > <br><br> > <a href="session_2.php">content page</a> > </body> > </html> > > ............... > //this is a revised script with a conditional else > //script session_1a.php > <?php > session_start(); > ?> > <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_products'])); > }else{ //this conditional has been added > $products = $_POST['form_products'] ; > } > $_SESSION['products'] = serialize($products); > print "<p>Your products have been registered!</p>"; > } > ?> > > <form method="POST" action="<?php $_SERVER[PHP_SELF] ?>"> > <P>Select some products:<br> > <select name="form_products[]" multiple size=3> > <option>Sonic Screwdriver</option> > <option>Hal 2000</option> > <option>Tardis</option> > <option>ORAC</option> > <option>Transporter bracelet</option> > </select> > <br><br> > <input type="submit" value="choose"> > </form> > <br><br> > <a href="session_2.php">content page</a> > </body> > </html> > .............. > //this is session_2.php > > <?php > session_start(); > ?> > <html> > <head> > <title>Listing 16.5 Accessing session variables</title> > </head> > <body> > <h1> Content Page</h1> > <?php > if (isset($_SESSION[products])) { > print "<b>Your cart:</b><ol>\n"; > foreach (unserialize($_SESSION[products]) as $p) { > print "<li>$p"; > } > print "</ol>"; > } > ?> > <a href="session_1.php">Back to product choice page</a> > </body> > </html>

« previous php.general (#170385) next »