[ciapug] Session Question: how to pass variables, well, 1st how to pass values
Barry Von Ahsen
ciapug@cialug.org
Tue, 24 Jun 2003 13:25:20 -0500
Agreed, it may be a tad harder, but it is better form, and it will always work.
You don't have to rely on server behavior that may change from host to host,
or even php version to version.
-barry
On Tue, Jun 24, 2003 at 12:52:55PM -0500, Dave J. Hala Jr. wrote:
> Its my opinion that when using your session variables you should always
> reference them using $_SESSION['myvar']
>
> If you do it this way it will eliminate the possiblity of an end user
> passing a value to your script.
>
>
>
>
>
>
>
> >
> >
> On Tue, 2003-06-24 at 12:00, Barry Von Ahsen wrote:
> > You should still register the variables in test.php, trial 1:
> > session_start();
> > session_register('myvar','mysession');
> >
> > $_SESSION['myvar']=2;
> > $_SESSION['mysession']="test";
> >
> > then test2.php should work:
> > session_start();
> > echo "session[myvar]= ".$_SESSION['myvar'];
> > echo "session[mysession]= ".$_SESSION['mysession'];
> >
> > and if register_globals is on, then test2.php should also work with just
> > session_start();
> > echo "myvar= ".$myvar;
> > echo "mysession= ".$mysession;
> >
> > (this all worked for me on php 4.2.0, register_globals=on)
> > -barry
> >
> >
> > On Mon, Jun 23, 2003 at 05:28:54PM -0500, Jane Swanson wrote:
> > > Hi, again. Newbie-me.
> > >
> > > My php is 4.1.2. Register_globals is turned on. My book is confusing about whether to register variables or not. The following two programs have some of my trials.
> > >
> > > Trial1/1 & Trial2/2 go together on the samples. For each of those I got no errors. The descriptions echoed but not the values.
> > >
> > > The top version was an attempt to register my session variables. The 'session_register' had to go on the first line or I got errors. If anything else was on the first line, it turned into trash displayed on the output page. With this version, test was ok but no values show on test2.
> > >
> > > Am I doing something wrong or is this another question for my hosting company? If the latter, please help me ask the right question.
> > >
> > > Thanks.
> > > Jbs
> > > test.php:
> > >
> > > #!/usr/local/bin/php <?php session_start(); session_register('myvar','mysession'); ?>
> > > <?
> > > $myvar = 2;
> > > $mysession = "test";
> > > echo 'value of \'myvar\' is '
> > > .$myvar.'<br />';
> > > echo 'value of \'mysession\' is '
> > > .$mysession.'<br />';
> > >
> > > // Trial2
> > > // #!/usr/local/bin/php <?php session_start(); //top line
> > > // $HTTP_SESSION_VARS['myvar'] = 2;
> > > // $HTTP_SESSION_VARS['mysession'] = "test";
> > > // echo 'value of $HTTP_SESSION_VARS[\'myvar\'] is '
> > > // .$HTTP_SESSION_VARS['myvar'].'<br />';
> > > // echo 'value of $HTTP_SESSION_VARS[\'mysession\'] is '
> > > // .$HTTP_SESSION_VARS['mysession'].'<br />';
> > > // trial1
> > > // #!/usr/local/bin/php <?php session_start(); //top line
> > > // $_SESSION['myvar'] = 2;
> > > // $_SESSION['mysession'] = "test";
> > > // echo 'value of $_SESSION[\'myvar\'] is '
> > > // .$_SESSION['myvar'].'<br />';
> > > // echo 'value of $_SESSION[\'mysession\'] is '
> > > // .$_SESSION['mysession'].'<br />';
> > >
> > > ?>
> > > <a href="test2.php">next</a>
> > >
> > > test2.php:
> > > #!/usr/local/bin/php <?php session_start(); ?>
> > > <?
> > > echo 'value of \'myvar\' is '
> > > .$myvar.'<br />';
> > > echo 'value of \'mysession\' is '
> > > .$mysession.'<br />';
> > >
> > > // trial2
> > > // echo 'value of $HTTP_SESSION_VARS[\'myvar\'] is '
> > > // .$HTTP_SESSION_VARS['myvar'].'<br />';
> > > // echo 'value of $HTTP_SESSION_VARS[\'mysession\'] is '
> > > // .$HTTP_SESSION_VARS['mysession'].'<br />';
> > > // Trial1
> > > // echo 'value of $_SESSION[\'myvar\'] is '
> > > // .$_SESSION['myvar'].'<br />';
> > > // echo 'value of $_SESSION[\'mysession\'] is '
> > > // .$_SESSION['mysession'].'<br />';
> > >
> > > ?>
> > >
> > >
> > >
> > >
> --
>
> "...Unix, MS-DOS and Windows NT (also known as the Good, the Bad, and the Ugly)"
>
> OSIS
> Dave J. Hala Jr.
> 641.485.1606
>
>
> _______________________________________________
> ciapug mailing list
> ciapug@cialug.org
> http://cialug.org/mailman/listinfo/ciapug
--
==================
Barry Von Ahsen
barry@vonahsen.com