Re: Different sessions, same client

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

 



On Sun, 2011-01-23 at 09:21 +0100, Thijs Lensselink wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 01/23/2011 07:33 AM, Paul M Foster wrote:
> > Storing any sort of login/auth data in cookies has regularly been panned
> > on this list. The preference seems to be to store whatever login/auth
> > information *must* be stored in the $_SESSION variable.
> > 
> > Well and good. My problem, however, is that I have multiple applications
> > in different tabs running on the same server, which may all use the same
> > sub-variables, like "username". As a result, they run into each other.
> > One application will think I'm logged in when I'm not logged in to that
> > application, but to another in the same browser on the same box.
> > 
> > So my question is how to prevent this using the standard PHP functions
> > relating to sessions. I'd like different applications in different tabs
> > on the same box/browser to have different sessions, so they don't share
> > data.
> > 
> > Thoughts?
> > 
> > Paul
> > 
> 
> 
> Using session_name will allow you to run two different sessions in the
> same browser.
> 
> session_name('app1');
> session_start();
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> 
> iQIcBAEBAgAGBQJNO+TpAAoJEMffsHAOnubXzHYQAI86mjCR49uWTPYweFim9e+K
> EtU4KnFfXkQj+Qp0YYjjuiAW0muRywbjKkwuAmw7fO/v9DrbGILAvnneNX7OR9cM
> TBh66J6anuLB3UmItrmFqP2VKgWaLG7KHf0wExfv3duzJkRqp5Y8NQG1Ep8aXA0U
> 8N2VHQ1ki9ukHeIWcPI4l5558j0NE/5BsiWgJIgTC/CovDjdNYln9vszkmFw0g2G
> vJore2V3OIBcmLhqpcITSNK4FcaNWIKnrRWnlCgoAzA1WUCQXnmv0nJMZ0P9xtzk
> iYt2lkBvlGEJ8lnZoAo83XRsQ1oI6vLFwf5xDkI4OGnAsOIzmX3RzStxXyz9o5th
> VyIHtj8R40Rk6eI6L5xE4w1l58JTFMPdgaFk5Ku/v8i8UGDWjWHC0Qhob14w+H32
> RQUtx9dBsYKYT9ZHIkxAQYDc9nTdgajRzo0ONqmzPTS9Qb7NTcjiC9pb1bHBjubA
> M4zJnyO5N7IUy0FmMyS7PG8saCgJDSYj+stvoCC9Kd0eDRBKs+M5cRLpnXem/Yf8
> KG+clIe5+7X9l1TC7uT84HxZYSZCcuwuvRyBUIZknagyREQvLhaFX1OPZ/vk3n6S
> j7k77oFpcCRjkPVKZeUqFAENEY1J7p6DBEkTz9gRkA+islnSIt8rjz+0wYYg0goy
> b3C3ThlftPWwcOBuRQOP
> =ZBm8
> -----END PGP SIGNATURE-----
> 


You can of course use arrays in your session as well:

$_SESSION['app_name'] = Array(
    'username' => 'John',
    'user_id' => 1234,
    'some other info' => 'another string',
);

I use this on my localhost sometimes, as it can be easier running tests
and stuff than having to create a whole new host entry for it in my
config files!

Thanks,
Ash
http://www.ashleysheridan.co.uk



[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