This is a discussion on 2 ways within the PHP Language forums, part of the PHP Programming Forums category; hi all, Having a session variable test . Is there a difference between: $test = "string"; or $_session['test'] = "...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Yep first of all $_session doesn't exist
$_SESSION does though, so lets not forget about case sensitivity. For portablity sake ALWAYS make sure you use $_SESSION['test']="string"; Especially if you're not sure what version of PHP the host is running, and/or what there php.ini reads like. Also if register globals is on and there is a $_POST['test'] or a $_GET['test'] you could get a conflicting variable that will be a HUGE pain in the ass to track down. Always best to test as far up the pipe as you can and then explicitly assign. I do it one of two ways, depending on what exactly I need. I call this extremely explicit if($_POST['test']){ $test = $_POST['test']; $_SESSION['test']=$test; }elseif($_GET['test']){ $test = $_GET['test']; $_SESSION['test']=$test; }elseif($_SESSION['test']){ $test = $test; $_SESSION['test']=$test; } Or the sloppy way extract($_SESSION); If register globals (I think thats it) is turned on $_SESSION['test'] will automagically update, otherwise $_SESSION['test']=$test; is the only way to go. Someone please correct me, on the register globals comment, if I'm wrong, but I know it's something. Anyways more details can be had here http://us2.php.net/manual/en/reserve...iables.session "Stijn Goris" <mepisto@hotmail.com> wrote in message news:<3f9d05d2$0$297$ba620e4c@reader3.news.skynet. be>... > hi all, > > Having a session variable test . > > Is there a difference between: > $test = "string"; > or > $_session['test'] = "string"; > > kind regards > Stijn |
|
|||
|
Uhm, this looks like assignment to me. A test would be conditional statment
like if. if ( $_SESSION['test'] == 'bigfatbooger') { do::someshit('bathroom'); } = ( Assignment ) == ( test for equality ) There is also tests for existance, TRUE/FALSE tests. if ($_SESSION['test']) { cook::food('pizza'); } else { pig::out('pork rinds'); } Make sense? Also, watch your case, no such monster as $_session, its $_SESSION. "Stijn Goris" <mepisto@hotmail.com> wrote in message news:3f9d05d2$0$297$ba620e4c@reader3.news.skynet.b e... > hi all, > > Having a session variable test . > > Is there a difference between: > $test = "string"; > or > $_session['test'] = "string"; > > kind regards > Stijn > > |
|
|||
|
I think what he means is, does $_SESSION automagically keep track of
it's member variables and update accordingly. The answer is, yes/no/maybe sometimes, it depends on the php version and it's config. The point I'm trying to make is this... Make sure assignment is ALWAYS pointing to exactly what you want to assign. Assuming $_SESSION['test'] ==1 $test = $_SESSION['test']; $test ++; Will produce one of two results. Either $test will now == 2 and $_SESSION['test'] ==2 Or $test ==2 and $_SESSION['test'] ==1 It would be best, to have done this instead $_SESSION['test'] ++; This way we now know for sure it == 2 By the way, just ignore my first post, it was WAY too early in the morning and I was kinda sleepy when I wrote it. "Brian" <cpnmscg02 (@) sneakemail.com> wrote in message news:<zBbnb.41390$Tr4.85919@attbi_s03>... > Uhm, this looks like assignment to me. A test would be conditional statment > like if. > > if ( $_SESSION['test'] == 'bigfatbooger') { > do::someshit('bathroom'); > } > > = ( Assignment ) > == ( test for equality ) > > There is also tests for existance, TRUE/FALSE tests. > > if ($_SESSION['test']) { > cook::food('pizza'); > } else { > pig::out('pork rinds'); > } > > Make sense? > > Also, watch your case, no such monster as $_session, its $_SESSION. > > "Stijn Goris" <mepisto@hotmail.com> wrote in message > news:3f9d05d2$0$297$ba620e4c@reader3.news.skynet.b e... > > hi all, > > > > Having a session variable test . > > > > Is there a difference between: > > $test = "string"; > > or > > $_session['test'] = "string"; > > > > kind regards > > Stijn > > > > |