[ciapug] Session Question: how to pass variables, well, 1st how to pass values
Barry Von Ahsen
ciapug@cialug.org
Tue, 24 Jun 2003 12:00:58 -0500
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 />';
>
> ?>
>
>
>
>
--
==================
Barry Von Ahsen
barry@vonahsen.com