Re: Can't copy a variable from one session to another?

From: Date: Fri, 09 Apr 2004 22:40:01 +0000
Subject: Re: Can't copy a variable from one session to another?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-183034@lists.php.net to get a copy of this message
After talking with some folks on IRC, it sounds like this is effectively impossible?? I'd just like to check -- is it really impossible in PHP to copy a variable from one session to another? I don't mind subtle trickery. Thanks, - Scott On Fri, 9 Apr 2004 02:37:05 -0700 (PDT) "Scott Bronson" <bronson@rinspin.com> wrote: > My web site currently uses 2 sessions: mine ("SBSESSID") and > SquirrelMail's ("SQMSESSID"). They work perfectly on their own. > However, I would like to allow the user to move from my area to > SquirrelMail without re-entering a password. Therefore, I need to copy > the password from my session to SquirrelMail's. I've been struggling with > this for most of the night but this is the closest I've come: > > tst.php: > > <?php > error_reporting(E_NONE); // suppress spurious cookie errors > header("content-type: text/plain"); > > /// set up original session, then close it > session_name("SESS1"); > session_start(); > print_r(session_name()); > echo " " . print_r($_SESSION,true) . "\n"; > session_write_close(); > session_unset(); > > // print new session, retrieve secret key, then close it. > session_name("SESS2"); > session_start(); > print_r(session_name()); > echo " " . print_r($_SESSION,true) . "\n"; > $secret = $_SESSION['password']; > session_write_close(); > session_unset(); > > // open old session. it should exactly match the original. > session_name("SESS1"); > session_start(); > print_r(session_name()); > echo " " . print_r($_SESSION,true) . "\n"; > ?> > > > When I run this after filling in the sessions, I get: > > SESS1 Array > ( > [squirrel] => mail > ) > > SESS2 Array > ( > [squirrel] => mail > ) > > SESS1 Array > ( > [squirrel] => mail > ) > > What's happening? The second time I call session_start(), instead of > getting SESS2 like I asked for, I'm just getting SESS1 again. Even if I > call error_reporting(E_ALL), I don't get any relevant error messages. Why > won't session_start() open the named session? > > When I replace the two calls to session_write_close() with > session_destroy(), I get this: > > SESS1 Array > ( > [squirrel] => mail > ) > > SESS2 Array > ( > [password] => whoa > ) > > SESS1 Array > ( > ) > > Which is correct, except that it destroys the sessions! So close and yet > so far. > > Does anybody know how I can do this? I'm stumped. Thanks! > > - Scott > > > To duplicate exactly what I did here, create 2 more scripts: > > s1.php: > > <?php > session_name("SESS1"); > session_start(); > $_SESSION["squirrel"] = "mail"; > print_r($_SESSION); > ?> > > > s2.php: > > <?php > session_name("SESS2"); > session_start(); > $_SESSION["password"] = "whoa"; > print_r($_SESSION); > ?> > > Now, open s1.php in your web browser. Then open s2. php. Finally, open > tst.php. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#183034) next »