[ciapug] Session Question: how to pass variables, well, 1st how to pass values
Jane Swanson
ciapug@cialug.org
Mon, 23 Jun 2003 17:28:54 -0500
This is a multi-part message in MIME format.
------=_NextPart_000_0396_01C339AC.EBD79C40
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
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. =20
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'); ?>
<?=20
$myvar =3D 2;
$mysession =3D "test";
echo 'value of \'myvar\' is '
.$myvar.'<br />';
echo 'value of \'mysession\' is '
.$mysession.'<br />';
=20
// Trial2
// #!/usr/local/bin/php <?php session_start(); //top line
// $HTTP_SESSION_VARS['myvar'] =3D 2;
// $HTTP_SESSION_VARS['mysession'] =3D "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'] =3D 2;
// $_SESSION['mysession'] =3D "test";
// echo 'value of $_SESSION[\'myvar\'] is '
// .$_SESSION['myvar'].'<br />';
// echo 'value of $_SESSION[\'mysession\'] is '
// .$_SESSION['mysession'].'<br />';
?>
<a href=3D"test2.php">next</a>
test2.php:
#!/usr/local/bin/php <?php session_start(); ?>
<?=20
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=20
// echo 'value of $_SESSION[\'myvar\'] is '
// .$_SESSION['myvar'].'<br />';
// echo 'value of $_SESSION[\'mysession\'] is '
// .$_SESSION['mysession'].'<br />';
=20
?>
------=_NextPart_000_0396_01C339AC.EBD79C40
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1170" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi, again. Newbie-me.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>My php is 4.1.2. Register_globals =
is turned=20
on. My book is confusing about whether to register variables or =
not. =20
The following two programs have some of my trials. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Trial1/1 & Trial2/2 go together on =
the=20
samples. For each of those I got no errors. The descriptions =
echoed=20
but not the values.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>The top version was an attempt to =
register my=20
session variables. The 'session_register' had to go on the first =
line or I=20
got errors. If anything else was on the first line, it turned into =
trash=20
displayed on the output page. With this version, test was ok but =
no values=20
show on test2.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Am I doing something wrong or is this =
another=20
question for my hosting company? If the latter, please help me ask =
the=20
right question.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Jbs</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>test.php:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>#!/usr/local/bin/php <?php=20
session_start(); session_register('myvar','mysession');=20
?><BR><? <BR> $myvar =3D 2;<BR> $mysession =3D =
"test";<BR> echo=20
'value of \'myvar\' is '<BR> .$myvar.'<br />';<BR> echo =
'value=20
of \'mysession\' is '<BR> .$mysession.'<br =
/>';<BR> <BR>//=20
Trial2<BR>// #!/usr/local/bin/php <?php=20
session_start(); //top=20
line<BR>// $HTTP_SESSION_VARS['myvar'] =3D=20
2;<BR>// $HTTP_SESSION_VARS['mysession'] =3D =
"test";<BR>// echo 'value=20
of $HTTP_SESSION_VARS[\'myvar\'] is=20
'<BR>// .$HTTP_SESSION_VARS['myvar'].'<br =
/>';<BR>// echo 'value=20
of $HTTP_SESSION_VARS[\'mysession\'] is=20
'<BR>// .$HTTP_SESSION_VARS['mysession'].'<br />';<BR>//=20
trial1<BR>// #!/usr/local/bin/php <?php=20
session_start(); &nb=
sp; =20
//top line<BR>// $_SESSION['myvar'] =3D =
2;<BR>// $_SESSION['mysession']=20
=3D "test";<BR>// echo 'value of $_SESSION[\'myvar\'] is=20
'<BR>// .$_SESSION['myvar'].'<br />';<BR>// echo 'value =
of=20
$_SESSION[\'mysession\'] is '<BR>// .$_SESSION['mysession'].'<br =
/>';</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>?><BR><a=20
href=3D"test2.php">next</a></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2><STRONG>test2.php:</STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>#!/usr/local/bin/php <?php=20
session_start(); ?><BR><? <BR> echo 'value of \'myvar\' =
is=20
'<BR> .$myvar.'<br />';<BR> echo 'value of \'mysession\' =
is=20
'<BR> .$mysession.'<br />';</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>// trial2<BR>// echo 'value of=20
$HTTP_SESSION_VARS[\'myvar\'] is=20
'<BR>// .$HTTP_SESSION_VARS['myvar'].'<br =
/>';<BR>// echo 'value=20
of $HTTP_SESSION_VARS[\'mysession\'] is=20
'<BR>// .$HTTP_SESSION_VARS['mysession'].'<br />';<BR>//=20
Trial1 <BR>// echo 'value of $_SESSION[\'myvar\'] is=20
'<BR>// .$_SESSION['myvar'].'<br />';<BR>// echo 'value =
of=20
$_SESSION[\'mysession\'] is '<BR>// .$_SESSION['mysession'].'<br =
/>';</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> <BR>?><BR></FONT><FONT =
face=3DArial=20
size=3D2></DIV>
<DIV><BR></DIV></FONT>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV></BODY></HTML>
------=_NextPart_000_0396_01C339AC.EBD79C40--