[PHP] Multiple sessions open at same time, is it possible?
Hello, I'm quite new to sessions, an am trying to program a script which needs two sessions ... I have a members area which uses 1 session, and when you click on disconnect it closes the session and the user returns to the login page. I also am programming a shopping cart so members can choose what they would like to download that also uses a session. All worked fine untill I realised that because they both use the same session, when I disconnect from the members area it also obviously deletes all elements from the download cart. I would there for need to have two seperate sessions one for the cart, and one for the members area. And sometimes I will need to have them both open. Is this possible ? I've searched google but not found anything interesting, except session_name, but I still don't know how to open two sessions or close one session but not the other, or open a variable in a specific session ... Thanks in advance, Richard -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple sessions open at same time, is it possible?
On 2 Mar 2008, at 14:49, Richard wrote: I'm quite new to sessions, an am trying to program a script which needs two sessions ... I have a members area which uses 1 session, and when you click on disconnect it closes the session and the user returns to the login page. I also am programming a shopping cart so members can choose what they would like to download that also uses a session. All worked fine untill I realised that because they both use the same session, when I disconnect from the members area it also obviously deletes all elements from the download cart. I would there for need to have two seperate sessions one for the cart, and one for the members area. And sometimes I will need to have them both open. Is this possible ? I've searched google but not found anything interesting, except session_name, but I still don't know how to open two sessions or close one session but not the other, or open a variable in a specific session ... Just use one session. Put the data for each session into a separate array... $_SESSION['members'] = array('lots', 'of', 'data'); $_SESSION['cart'] = array('lots', 'of', 'money-making', 'crap'); To disconnect the user from one or other simply unset that variable... unset($_SESSION['members']); unset($_SESSION['cart']); KISS. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple sessions open at same time, is it possible?
Stut a écrit : On 2 Mar 2008, at 14:49, Richard wrote: I'm quite new to sessions, an am trying to program a script which needs two sessions ... I have a members area which uses 1 session, and when you click on disconnect it closes the session and the user returns to the login page. I also am programming a shopping cart so members can choose what they would like to download that also uses a session. All worked fine untill I realised that because they both use the same session, when I disconnect from the members area it also obviously deletes all elements from the download cart. I would there for need to have two seperate sessions one for the cart, and one for the members area. And sometimes I will need to have them both open. Is this possible ? I've searched google but not found anything interesting, except session_name, but I still don't know how to open two sessions or close one session but not the other, or open a variable in a specific session ... Just use one session. Put the data for each session into a separate array... $_SESSION['members'] = array('lots', 'of', 'data'); $_SESSION['cart'] = array('lots', 'of', 'money-making', 'crap'); To disconnect the user from one or other simply unset that variable... unset($_SESSION['members']); unset($_SESSION['cart']); KISS. -Stut Thankyou, instead of unsetting the whole session, I just unset de password, so the user has to login again and now it does not reset the cart anymore. However, is there a way to limit the session stay alive time for just one variable ? If for example, if a user has not done anything in his members area for more than 30 minutes I would like to be able to reset his password, but I do not want to reset the cart. Do I have to program this seperatly in PHP (IE set a session varibale $_SESSION['last_time'] = time(); and on each page loads : if ( time() - $_SESSION[last_time] 1800) { $_SESSION['password'] = array(); else { $_SESSION['last_time'] = time() } ... Or is there a better way to do this? Thanks again :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple sessions open at same time, is it possible?
On 2 Mar 2008, at 15:28, Richard wrote: Stut a écrit : On 2 Mar 2008, at 14:49, Richard wrote: I would there for need to have two seperate sessions one for the cart, and one for the members area. And sometimes I will need to have them both open. Is this possible ? I've searched google but not found anything interesting, except session_name, but I still don't know how to open two sessions or close one session but not the other, or open a variable in a specific session ... Just use one session. Put the data for each session into a separate array... $_SESSION['members'] = array('lots', 'of', 'data'); $_SESSION['cart'] = array('lots', 'of', 'money-making', 'crap'); To disconnect the user from one or other simply unset that variable... unset($_SESSION['members']); unset($_SESSION['cart']); KISS. However, is there a way to limit the session stay alive time for just one variable ? If for example, if a user has not done anything in his members area for more than 30 minutes I would like to be able to reset his password, but I do not want to reset the cart. Do I have to program this seperatly in PHP (IE set a session varibale $_SESSION['last_time'] = time(); and on each page loads : if ( time() - $_SESSION[last_time] 1800) { $_SESSION['password'] = array(); else {$_SESSION['last_time'] = time() } ... Or is there a better way to do this? There is no built-in mechanism for this so you need to implement your own as above. Personally I would store it as an expiry time rather than the current time, but whatever floats ya boat. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple sessions open at same time, is it possible?
Stut a écrit : On 2 Mar 2008, at 15:28, Richard wrote: Stut a écrit : On 2 Mar 2008, at 14:49, Richard wrote: I would there for need to have two seperate sessions one for the cart, and one for the members area. And sometimes I will need to have them both open. Is this possible ? I've searched google but not found anything interesting, except session_name, but I still don't know how to open two sessions or close one session but not the other, or open a variable in a specific session ... Just use one session. Put the data for each session into a separate array... $_SESSION['members'] = array('lots', 'of', 'data'); $_SESSION['cart'] = array('lots', 'of', 'money-making', 'crap'); To disconnect the user from one or other simply unset that variable... unset($_SESSION['members']); unset($_SESSION['cart']); KISS. However, is there a way to limit the session stay alive time for just one variable ? If for example, if a user has not done anything in his members area for more than 30 minutes I would like to be able to reset his password, but I do not want to reset the cart. Do I have to program this seperatly in PHP (IE set a session varibale $_SESSION['last_time'] = time(); and on each page loads : if ( time() - $_SESSION[last_time] 1800) { $_SESSION['password'] = array(); else {$_SESSION['last_time'] = time() } ... Or is there a better way to do this? There is no built-in mechanism for this so you need to implement your own as above. Personally I would store it as an expiry time rather than the current time, but whatever floats ya boat. -Stut Sorry, I only know how to use current time, just for my personal interest, how would you use expiry time ? I've looked around a bit and can't work out how you would do this without using the current time... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple sessions open at same time, is it possible?
On 2 Mar 2008, at 15:59, Richard wrote: Stut a écrit : On 2 Mar 2008, at 15:28, Richard wrote: However, is there a way to limit the session stay alive time for just one variable ? If for example, if a user has not done anything in his members area for more than 30 minutes I would like to be able to reset his password, but I do not want to reset the cart. Do I have to program this seperatly in PHP (IE set a session varibale $_SESSION['last_time'] = time(); and on each page loads : if ( time() - $_SESSION[last_time] 1800) { $_SESSION['password'] = array(); else {$_SESSION['last_time'] = time() } ... Or is there a better way to do this? There is no built-in mechanism for this so you need to implement your own as above. Personally I would store it as an expiry time rather than the current time, but whatever floats ya boat. Sorry, I only know how to use current time, just for my personal interest, how would you use expiry time ? I've looked around a bit and can't work out how you would do this without using the current time... It's really not rocket science... if ($_SESSION['expiry'] time()) { $_SESSION['password'] = array(); } else { // Password expires in 30 minutes $_SESSION['expiry'] = time() + 1800; } Just curious... why are you setting the password to an empty array? You'd probably be better off unset'ing it so you can use isset to check for it. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple sessions open at same time, is it possible? [ Solved, thankyou !]
Stut a écrit : On 2 Mar 2008, at 15:59, Richard wrote: Stut a écrit : On 2 Mar 2008, at 15:28, Richard wrote: However, is there a way to limit the session stay alive time for just one variable ? If for example, if a user has not done anything in his members area for more than 30 minutes I would like to be able to reset his password, but I do not want to reset the cart. Do I have to program this seperatly in PHP (IE set a session varibale $_SESSION['last_time'] = time(); and on each page loads : if ( time() - $_SESSION[last_time] 1800) { $_SESSION['password'] = array(); else {$_SESSION['last_time'] = time() } ... Or is there a better way to do this? There is no built-in mechanism for this so you need to implement your own as above. Personally I would store it as an expiry time rather than the current time, but whatever floats ya boat. Sorry, I only know how to use current time, just for my personal interest, how would you use expiry time ? I've looked around a bit and can't work out how you would do this without using the current time... It's really not rocket science... if ($_SESSION['expiry'] time()) { $_SESSION['password'] = array(); } else { // Password expires in 30 minutes $_SESSION['expiry'] = time() + 1800; } Just curious... why are you setting the password to an empty array? You'd probably be better off unset'ing it so you can use isset to check for it. -Stut Oh right ! :) Yes you're right about the array, I used it by mistake, as to reset a value in $_SESSION[cart] , ie : $_SESSION['cart']['item_number'] I had to do $_SESSION['cart']['item_number'] = array(); as unset would anly work for unsetting the whole cart and not just one item, but yes it would be best to use unset for $_SESSION['password'] ! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple sessions open at same time, is it possible? [ Solved, thankyou !]
On 2 Mar 2008, at 16:32, Richard wrote: Stut a écrit : Just curious... why are you setting the password to an empty array? You'd probably be better off unset'ing it so you can use isset to check for it. Oh right ! :) Yes you're right about the array, I used it by mistake, as to reset a value in $_SESSION[cart] , ie : $_SESSION['cart']['item_number'] I had to do $_SESSION['cart']['item_number'] = array(); as unset would anly work for unsetting the whole cart and not just one item, but yes it would be best to use unset for $_SESSION['password'] ! Eh? What's in $_SESSION['cart']['item_number']? You might want to consider one of the following depending on what's in that array element... unset($_SESSION['cart']['item_number']); unset($_SESSION['cart'][array_search($itemtoremove, $_SESSION['cart'])]); unset($_SESSION['cart']['item_number'][array_search($itemtoremove, $_SESSION['cart']['item_number'])]); At the very least it would be better to use null rather than array(), but actually removing the item from the array would be my recommendation. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple sessions open at same time, is it possible? [ Solved, thankyou !]
Stut a écrit : On 2 Mar 2008, at 16:32, Richard wrote: Stut a écrit : Just curious... why are you setting the password to an empty array? You'd probably be better off unset'ing it so you can use isset to check for it. Oh right ! :) Yes you're right about the array, I used it by mistake, as to reset a value in $_SESSION[cart] , ie : $_SESSION['cart']['item_number'] I had to do $_SESSION['cart']['item_number'] = array(); as unset would anly work for unsetting the whole cart and not just one item, but yes it would be best to use unset for $_SESSION['password'] ! Eh? What's in $_SESSION['cart']['item_number']? You might want to consider one of the following depending on what's in that array element... unset($_SESSION['cart']['item_number']); unset($_SESSION['cart'][array_search($itemtoremove, $_SESSION['cart'])]); unset($_SESSION['cart']['item_number'][array_search($itemtoremove, $_SESSION['cart']['item_number'])]); At the very least it would be better to use null rather than array(), but actually removing the item from the array would be my recommendation. -Stut Sorry I went back to where I read that I should use =array(); and I miss read an instruction which was : http://fr3.php.net/unset | |Quote from http://fr.php.net/session_unset Do NOT unset the whole $_SESSION with unset($_SESSION) as this will disable the registering of session variables through the $_SESSION superglobal. So basically don't do: unset($_SESSION) Instead do: $_SESSION = array();| So no need for setting my session variables to array()... | -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Multiple sessions
Hi. Is there a way to have multiple sessions open in one browser (specifically, Firefox or Safari)? For example, IE does not transfer session data from one window to another, however, Firefox does. So, if one user opens a session and then his/her friend wants to open a different session of that same program on the same computer, (s)he is not able to without overwriting the first session data. I have thought of one solution, but have yet to test it. Upon the first user logging in, I could assign them as session ID (along with the one that PHP creates). I could then verify that ID is being used on each page. For the second user, I could create a different one and do the same as the first. ? // User 1 $_SESSION[my_special_id] = abcd; // created upon logging in if ($_SESSION[is_logged_in] $_SESSION[my_special_id] == $_GET[my_special_id]) { // do stuff } ? ? // User 2 in a different window of Firefox $_SESSION[my_special_id] = efgh; // created upon logging in if ($_SESSION[is_logged_in] $_SESSION[my_special_id] == $_GET[my_special_id]) { // do stuff } ? Notice that they both share the same is_logged_in variable, but a different my_special_id variable. Actually, I just noticed something. If User 1 logs out and kills is_logged_in, that would also kill it for User 2. I don't know. I've confused myself now. Any suggestions? Common practices? Thanks in advance, ~Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple sessions
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Philip Thompson wrote: Is there a way to have multiple sessions open in one browser (specifically, Firefox or Safari)? For example, IE does not transfer session data from one window to another, however, Firefox does. So, if Not strictly true. It's actually based on instances. Firefox differs from IE because if you start a new Firefox instance it joins the existing instance if it exists. IE does not do this. To get the 'shared' session in IE open a new window from the existing window instead of starting a new copy of IE. one user opens a session and then his/her friend wants to open a different session of that same program on the same computer, (s)he is not able to without overwriting the first session data. I have thought of one solution, but have yet to test it. Upon the first user logging in, I could assign them as session ID (along with the one that PHP creates). I could then verify that ID is being used on each page. For the second user, I could create a different one and do the same as the first. ? // User 1 $_SESSION[my_special_id] = abcd; // created upon logging in if ($_SESSION[is_logged_in] $_SESSION[my_special_id] == $_GET[my_special_id]) { // do stuff } ? ? // User 2 in a different window of Firefox $_SESSION[my_special_id] = efgh; // created upon logging in if ($_SESSION[is_logged_in] $_SESSION[my_special_id] == $_GET[my_special_id]) { // do stuff } ? Notice that they both share the same is_logged_in variable, but a different my_special_id variable. Actually, I just noticed something. If User 1 logs out and kills is_logged_in, that would also kill it for User 2. I'm confused as to why you need a solution to this 'problem'. How likely is it that you'll have 2 users trying to access your site on the same machine at the same time? If it is likely (although I don't see how) then you need to design your session data as an array keyed on the username, but that would be very insecure. In short are you trying to solve a perceived problem when no such problem actually exists? Think about it for a while before jumping to working around it. - -Stut -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEtT0dP9na3/DT5jQRAmUmAJ0XzG3ukmU4q6e7f6S1OrTtZ65M9QCfRbuj NSa/LAreelZGRLGysXGFMsU= =pzC4 -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple sessions
Stut wrote: I'm confused as to why you need a solution to this 'problem'. How likely is it that you'll have 2 users trying to access your site on the same machine at the same time? If it is likely (although I don't see how) then you need to design your session data as an array keyed on the username, but that would be very insecure. In short are you trying to solve a perceived problem when no such problem actually exists? Think about it for a while before jumping to working around it. There are times when it's handy, but not often. For example, when I'm debugging my code it is useful to be able to log into my application's admin module (which uses sessions to ensure admin rights) without blowing away my user session. In my case, I flick between Firefox and Konqueror. It would be nice to be able to separate the sessions generally though. The case where you have several accounts is just one example. Regards, Austin. signature.asc Description: OpenPGP digital signature
Re: [PHP] Multiple sessions
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Austin Denyer wrote: Stut wrote: I'm confused as to why you need a solution to this 'problem'. How likely is it that you'll have 2 users trying to access your site on the same machine at the same time? If it is likely (although I don't see how) then you need to design your session data as an array keyed on the username, but that would be very insecure. In short are you trying to solve a perceived problem when no such problem actually exists? Think about it for a while before jumping to working around it. There are times when it's handy, but not often. For example, when I'm debugging my code it is useful to be able to log into my application's admin module (which uses sessions to ensure admin rights) without blowing away my user session. In my case, I flick between Firefox and Konqueror. I do this by giving the admin session a custom name. That way it doesn't trample over the user session. It would be nice to be able to separate the sessions generally though. The case where you have several accounts is just one example. If this is the case you want to handle then having a single session var which is an array of arrays of session vars keyed on the username will solve this problem, but it's your choice to needlessly over-complicate the situation. Personally I think it's reasonable to expect people to log out of one account before they can log in with another. - -Stut -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEtVdO2WdB7L+YMm4RAntrAKDQoIdN8uTr3WSQygxPvq7zE+a5AACgzWEr BL/5GBUoopy+RNY6Emq7BLQ= =okNy -END PGP SIGNATURE- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] multiple sessions on same server/domain
ok i have one server with a single domain, each user have it's home with a public_html so i get mydomain.com/~user1/ and mydomain.com/~user2/ and so on. but each user might like to use sessions so how can i make it work so that sessions would have each one it's own variables and all...?? thanks, valter. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] multiple sessions
Hi, all -- I am trying to integrate phpbb into our web site and do so such that we set the login info before getting into the forum. We have a user 'x' who has a numeric user_id 'y' in the phpbb system that we'll need to set. We store that user_id in our system for other uses as well. Our cookie is simply named PHPSESSID and we usually see the session data by looking in $_SESSION. The phpbb cookie is named phpbb2mysql_data and has other good stuff in it. When I am in the phpbb code I want to be able to look at the PHPSESSID session data so that I can extract the user_id and pre-set it and then go on to create the phpbb cookie and so on. When I get there, though, I find that $_SESSION is empty. How do I look at the data stored in another cookie or session -- if I'm even using the terminology correctly? TIA HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature