Re: session question

From: Date: Fri, 23 Feb 2001 21:10:36 +0000
Subject: Re: session question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41378@lists.php.net to get a copy of this message
some comments on sessions - $PHPSESSID will only be set after the first page refresh. - SID will only be set if your not using cookies. - sessions with not transfer across multiple domain names. - sessions without cookies will not transfer accross full urls. <?php if (isset($PHPSESSID)) session_start($PHPSESSID); else session_start(); $PHPSESSID = session_id(); $SID = "PHPSESSID=$PHPSESSID"; ?> use this code and - sessions will transfer across full urls when using $SID - sessions will transer across multiple domain names on the same server using $SID - both $PHPSESSID and $SID are set allways set. remember that header redirects *require* full urls so you will have to use $SID. header("Location: http://$SERVER_NAME/index.php?$SID"); -- Chris Lee Mediawaveonline.com ph. 250.377.1095 ph. 250.376.2690 fx. 250.554.1120 lee@mediawaveonline.com ""Jon Rosenberg"" <php@columbusinteractive.com> wrote in message news:001301c09dc9$fc471c80$0e00000a@mainstreams.com... > I have a form that submits to abc.php which then calls db.php and db.php > then redirects to a new URL. I have session_start(); on all these files and > I'm registering the variables I need. It seems that the session dies or > gets lost on it's way through all the included files. I then tried to pass > the SID in the URL that the db.php file creates, but the SID is empty once > it gets here...though, there is a SID befoer then. Can sessions not be used > with multple include files? What could I be doing wrong? This is my first > forray into sessions...be gentle! > > thanks! > > Some code below, it's prettry straight forward. I still have cookies > enabled, as well. Do I need to disable cookies for the SID in URL method to > work? > > index.php where they log in from > <? > session_start(); //first line of file > ?> > <form method="POST" action="main.php"> > <input type="hidden" value="lrlogin" name="form_action"> > Username&nbsp;&nbsp;<input type="text" name="username" > class="color"><br /> > Password&nbsp;&nbsp;<input class="color" type="password" name="password"><br > /> > <input type="reset">&nbsp;&nbsp;&nbsp;<input > type="submit" value="Login"> > > code from main.php > <? > session_register(); > require ("db.php"); > if $form_action == "lrlogin" > { > get_user($username,$password); > } > ?> > > code from db.php > <? > session_start(); > SQL to select user info from db > $access = $row[access_level]; //etc getting vars from db > session_register("username"); > session_register("password"); > session_register("access"); > session_register("active"); > > header("Location:http://www.blah.com/index2.php?=".SID); > exit; > ?> > > index2.php code > <? > session_start(); > > print "Welcome $username"; > ?> > > it only prints Welcome ...no username :( > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#41378) next »