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 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> global=20
$id;<BR> $db =3D new =
FumarelDb();<BR> <BR> $query=3D"select=20
cod_usuario <BR> from usuarios=20
<BR> where username=3D'$user' and=20
pwd=3D'$pwd'";<BR> <BR> if(!$db->query($query)&g=
t;0)<BR> return=20
false;<BR> <BR> $db->next();<BR> <BR> =
$id=3D$db->f("cod_usuario");<BR> session_start();<BR> sessio=
n_register("id");<BR> return=20
$id;<BR>}</FONT></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>and then in the other page 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> global=20
$id;<BR> session_start();<BR> if(!session_is_registered("id"))<=
BR> return=20
false;<BR><BR> echo $id; <BR> 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> session_start();<BR> if(!session_is_registered(=
"id"))<BR> return=20
false;<BR> global $id;<BR><BR> echo=20
$id; <BR> return $id;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV> </DIV>
<DIV>outputs the rigth id...</DIV>
<DIV>Why? what am i doing wrong??</DIV></FONT></DIV></BODY></HTML>
------=_NextPart_000_031A_01BFD62E.0BD23B30--