RE: Sessions and multiple windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm



On 07 December 2004 12:50, Rory McKinley wrote:

[....]

> Page_3.php starts, unserializes $_SESSION['policeman'], and begins a
> lengthy SQL query that will take a few minutes to complete.
> 
> The user wants to do something else so he\she opens a new window for
> page_9.php (at this point page_3.php has yet to complete).
> 
> Now, the question is, what will PHP do when it starts with
> page_9? Will
> it unserialize $_SESSION['policeman'] again, even though it
> already has
> an unserialized instance of $_SESSION['policeman']? If it does
> unserialize, does that mean that it creates a second instance of
> $_SESSION['policeman'], thereby breaking the common link that I am
> trying to provide? 

Basically, this is a "that's not how it works" answer.  The fundamental
point you have to realise is that every php page is completely independent,
and nothing you can do in one can directly affect anything in another (even
if they use the same script to generate their output).  The ways of sending
information from one (invocation of a) script to another all use some
external medium: POST or GET variables, a SESSION, a database, or COOKIES.
Of these, only the database is purely server-side; the session very nearly
is, maintaining only the session id client-side; whilst GET, POST and
COOKIES all involve a full round-trip to the client.  (On the client side,
of course, you can use JavaScript to affect multiple windows, but that has
nothing to do with server-side PHP.)

So the answers to your specific questions are: yes, page_9 will unserialize
again (because it knows nothing of the page_3 instance -- whatever the "it"
is you're thinking of that "already has an unserialized instance", it
doesn't exist); and yes, a second, completely independent, instance will be
created, because there is no such common link in the way you appear to be
thinking of it.

Another kicker is that only one script can access the session data at any
one time -- in your scenario, page_9 will stall at session_start() until
page_3 releases the session lock.  This will be at the end of the page_3
script, unless you explicitly release it earlier with a
session_write_close(), for example.  If you do this, and the page_9 script
starts before the page_3 script has finished, you will have two, completely
separate, local instances of $_SESSION['policeman'].

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@xxxxxxxxxxxxxx
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux