[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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>My php is 4.1.2.&nbsp; Register_globals =
is turned=20
on.&nbsp; My book is confusing about whether to register variables or =
not.&nbsp;=20
The following two programs have some of my trials.&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Trial1/1 &amp; Trial2/2 go together on =
the=20
samples.&nbsp; For each of those I got no errors.&nbsp; The descriptions =
echoed=20
but not the values.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The top version was an attempt to =
register my=20
session variables.&nbsp; The 'session_register' had to go on the first =
line or I=20
got errors.&nbsp; If anything else was on the first line, it turned into =
trash=20
displayed on the output page.&nbsp; With this version, test was ok but =
no values=20
show on test2.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Am I doing something wrong or is this =
another=20
question for my hosting company?&nbsp; If the latter, please help me ask =
the=20
right question.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>#!/usr/local/bin/php &lt;?php=20
&nbsp;session_start(); &nbsp;session_register('myvar','mysession');=20
?&gt;<BR>&lt;? <BR>&nbsp;$myvar =3D 2;<BR>&nbsp;$mysession =3D =
"test";<BR>&nbsp;echo=20
'value of \'myvar\' is '<BR>&nbsp;.$myvar.'&lt;br /&gt;';<BR>&nbsp;echo =
'value=20
of \'mysession\' is '<BR>&nbsp;.$mysession.'&lt;br =
/&gt;';<BR>&nbsp;<BR>//=20
Trial2<BR>//&nbsp;&nbsp;&nbsp;#!/usr/local/bin/php &lt;?php=20
&nbsp;session_start();&nbsp;&nbsp;//top=20
line<BR>//&nbsp;$HTTP_SESSION_VARS['myvar'] =3D=20
2;<BR>//&nbsp;$HTTP_SESSION_VARS['mysession'] =3D =
"test";<BR>//&nbsp;echo 'value=20
of $HTTP_SESSION_VARS[\'myvar\'] is=20
'<BR>//&nbsp;.$HTTP_SESSION_VARS['myvar'].'&lt;br =
/&gt;';<BR>//&nbsp;echo 'value=20
of $HTTP_SESSION_VARS[\'mysession\'] is=20
'<BR>//&nbsp;.$HTTP_SESSION_VARS['mysession'].'&lt;br /&gt;';<BR>//=20
trial1<BR>//&nbsp;&nbsp;#!/usr/local/bin/php &lt;?php=20
&nbsp;session_start();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
//top line<BR>//&nbsp;$_SESSION['myvar'] =3D =
2;<BR>//&nbsp;$_SESSION['mysession']=20
=3D "test";<BR>//&nbsp;echo 'value of $_SESSION[\'myvar\'] is=20
'<BR>//&nbsp;.$_SESSION['myvar'].'&lt;br /&gt;';<BR>//&nbsp;echo 'value =
of=20
$_SESSION[\'mysession\'] is '<BR>//&nbsp;.$_SESSION['mysession'].'&lt;br =

/&gt;';</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>?&gt;<BR>&lt;a=20
href=3D"test2.php"&gt;next&lt;/a&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2><STRONG>test2.php:</STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>#!/usr/local/bin/php &lt;?php=20
&nbsp;session_start(); ?&gt;<BR>&lt;? <BR>&nbsp;echo 'value of \'myvar\' =
is=20
'<BR>&nbsp;.$myvar.'&lt;br /&gt;';<BR>&nbsp;echo 'value of \'mysession\' =
is=20
'<BR>&nbsp;.$mysession.'&lt;br /&gt;';</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>// trial2<BR>//&nbsp;echo 'value of=20
$HTTP_SESSION_VARS[\'myvar\'] is=20
'<BR>//&nbsp;.$HTTP_SESSION_VARS['myvar'].'&lt;br =
/&gt;';<BR>//&nbsp;echo 'value=20
of $HTTP_SESSION_VARS[\'mysession\'] is=20
'<BR>//&nbsp;.$HTTP_SESSION_VARS['mysession'].'&lt;br /&gt;';<BR>//=20
Trial1&nbsp;<BR>//&nbsp;echo 'value of $_SESSION[\'myvar\'] is=20
'<BR>//&nbsp;.$_SESSION['myvar'].'&lt;br /&gt;';<BR>//&nbsp;echo 'value =
of=20
$_SESSION[\'mysession\'] is '<BR>//&nbsp;.$_SESSION['mysession'].'&lt;br =

/&gt;';</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;<BR>?&gt;<BR></FONT><FONT =
face=3DArial=20
size=3D2></DIV>
<DIV><BR></DIV></FONT>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0396_01C339AC.EBD79C40--