You are here: Re: $_SESSION issue « PHP Programming Language « IT news, forums, messages
Re: $_SESSION issue

Posted by Peter Fox on 12/22/05 12:13

Following on from Tom's message. . .
>I put together a code that checks for 2 post variables then stores them
>in a multi-dim $_SESSION array, something like this:
>
>If ( isset($_POST['value_a'] && isset($_POST['value_b']) )
>{
> $_SESSION['value']['a'] = $_POST['value_a'];
> $_SESSION['value']['b'] = $_POST['value_b'];
>}
>
>The problem was that $_SESSION['value']['b'] was being overwritten with
>the value for 'a' so that both $_SESSION['value'] vars ended up being
>the same (i.e. $_POST['value_b']. I thoroughly tested it to confirm
>that this was what happening.

The following code works 'as advertised':
<?php
$SES['value']['a'] = 'va';
$SES['value']['b'] = 'vb';
print_r($SES);
?>
to give
Array ( [value] => Array ( [a] => va [b] => vb ) )

It works with $_SESSION too.

Are you operating in a foreach loop? If so this is a Gotcha.

Although not particularly related to this problem but in a similar vein:
Look up "variable variables" in the manual.

// convert $ay['foo'] into $foo
foreach($ay as $key => $val) {$$key = $ay[$key];}






--
PETER FOX Not the same since the bookshop idea was shelved
peterfox@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>

 

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

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