Session Question

[email protected] (Sergio GarcĂ­a Murillo) Wed, 14 Jun 2000 18:26:24 +0200
Newsgroups php.version4
Message-ID <031d01bfd61d$4923ecb0$3700000a@valinor>
------=_NextPart_000_031A_01BFD62E.0BD23B30
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I have a funciton in the begining of the page which checks that a =
variable "id" is registered in a session..
in the first pagei strat a new session and set the idto 1 and register =
the variable..
function set_id($user,$pwd)
{
 global $id;
 $db =3D new FumarelDb();
=20
 $query=3D"select  cod_usuario=20
   from  usuarios=20
   where username=3D'$user' and pwd=3D'$pwd'";
  =20
 if(!$db->query($query)>0)
  return false;
 =20
 $db->next();
 =20
 $id=3D$db->f("cod_usuario");
 session_start();
 session_register("id");
 return $id;
}


and then in the other page trying this way
function get_id()
{
 global $id;
 session_start();
 if(!session_is_registered("id"))
  return false;

 echo $id; =20
 return $id;
}
doesn't output nothing .. but changing the global line..
function get_id()
{
  session_start();
 if(!session_is_registered("id"))
  return false;
    global $id;

 echo $id; =20
 return $id;
}

outputs the rigth id...
Why? what am i doing wrong??

------=_NextPart_000_031A_01BFD62E.0BD23B30
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 content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I have a funciton in the begining of =
the page which=20
checks that a variable "id" is registered in a session..</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>in the&nbsp;first pagei strat a new =
session and set=20
the idto 1 and register the variable</FONT><FONT face=3DArial=20
size=3D2>..</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>function =
set_id($user,$pwd)<BR>{<BR>&nbsp;global=20
$id;<BR>&nbsp;$db =3D new =
FumarelDb();<BR>&nbsp;<BR>&nbsp;$query=3D"select=20
&nbsp;cod_usuario <BR>&nbsp;&nbsp;&nbsp;from &nbsp;usuarios=20
<BR>&nbsp;&nbsp;&nbsp;where&nbsp;username=3D'$user' and=20
pwd=3D'$pwd'";<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;if(!$db-&gt;query($query)&g=
t;0)<BR>&nbsp;&nbsp;return=20
false;<BR>&nbsp;&nbsp;<BR>&nbsp;$db-&gt;next();<BR>&nbsp;&nbsp;<BR>&nbsp;=
$id=3D$db-&gt;f("cod_usuario");<BR>&nbsp;session_start();<BR>&nbsp;sessio=
n_register("id");<BR>&nbsp;return=20
$id;<BR>}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>and then in the other page&nbsp;trying =
this=20
way</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>function get_id()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;global=20
$id;<BR>&nbsp;session_start();<BR>&nbsp;if(!session_is_registered("id"))<=
BR>&nbsp;&nbsp;return=20
false;<BR><BR>&nbsp;echo $id;&nbsp;&nbsp;<BR>&nbsp;return =
$id;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>doesn't output nothing .. but changing =
the global=20
line..</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>function get_id()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;session_start();<BR>&nbsp;if(!session_is_registered(=
"id"))<BR>&nbsp;&nbsp;return=20
false;<BR>&nbsp;&nbsp;&nbsp; global $id;<BR><BR>&nbsp;echo=20
$id;&nbsp;&nbsp;<BR>&nbsp;return $id;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>outputs the rigth id...</DIV>
<DIV>Why? what am i doing wrong??</DIV></FONT></DIV></BODY></HTML>

------=_NextPart_000_031A_01BFD62E.0BD23B30--