Page 1 of 2
Carry session to new browser
Posted: Thu Sep 01, 2005 10:30 pm
by Jim_Bo
Hi,
I have a shopping cart using session, when a new user adds products to the cart and proceeds to the checkout they need to create and account before they can continue. With the membership system after they signup they then get an email asking them to activate their account, therefore opening a new browser their cart data will be lost.
Can you carry the session data across in the url?
I tried:
Code: Select all
http://www.url.com/index.php?action=activate&id=$userid&code=$npassword&PHPSESSID=$sid
but once activated the cart data is lost.
Also how is it done so when they continue to the cart and need to login, have it so after login they are redirected back to the checkout page using header() ?
Thanks
Posted: Thu Sep 01, 2005 10:40 pm
by feyd
store the cart in the database using the session ID, and their user id. Require them to be logged in before the session ID could even match.
Posted: Thu Sep 01, 2005 10:46 pm
by Jim_Bo
Hi,
Sorry thats gone over my head ..
I have the cart and user data stored once checkout.php is successfully run.
Am I not clear with my explaination .. or have I missed your point?
Thanks
Posted: Thu Sep 01, 2005 11:13 pm
by josh
You can carry the SID identifier in the URL, yes.
What may have happened is PHP garbage collected the session, perhaps. Ensure the SID identifier is properly outputted into the email link you are sending. Then do a test, navigate to your sessions folder (you can find this with phpinfo()), delete all the sessions, ensure no one else is using the system while you perform this test, run through your script and then check to see PHP created the session, close your browser window, then click the link in your email verifying that the SID was sent in the URL correctly, make sure the session is still there. If it is not, try making a custom save_handler for your sessions to ensure they do not get cleaned out too often, if it is still there, it is a problem with your code in which case we cannot help you without more information.
Also, what feyd was trying to say is store the session id with the shopping cart information, and require the user to login before trying to match session id's
Posted: Thu Sep 01, 2005 11:16 pm
by feyd
store the data during the process between the cart and the checkout, not in the checkout. It must happen before or during the user creation happens.
Posted: Thu Sep 01, 2005 11:40 pm
by Jim_Bo
Hi,
Using
Code: Select all
http://www.url.com/index.php?action=activate&id=$userid&code=$npassword&PHPSESSID=$sid
the session id parsed to the email matched the session id as I echoed it out to check as well.
Am I ment to $_GET the session id in the new browser at all?
or should it process that all automatically?
Thanks
Posted: Thu Sep 01, 2005 11:48 pm
by josh
PHP should be propagating the SID for you automatically
Posted: Thu Sep 01, 2005 11:52 pm
by Jim_Bo
Hi
Also im trying to grab the url using
$page = $_SERVER['PHP_SELF'];
but when I echo $page it only returns /index.php but the url was actually /index.php?action=checkout
how do you grab the complete url?
Thanks
Posted: Thu Sep 01, 2005 11:54 pm
by feyd
look at what $_SERVER has in it.
Posted: Thu Sep 01, 2005 11:54 pm
by josh
that is the complete url
what you want is the 'query string'
$query_string = $_SERVER[''QUERY_STRING'']
Edit: damn feyd's fast
Posted: Fri Sep 02, 2005 12:26 am
by Jim_Bo
Hi,
I have been trying to have it so when a member logs in, it takes them back to the page prior to them logging in. All the pages that may ask them to login contain require 'login.php'; except the login link itself.
How is this done, same as when go to post in a forum, it takes you to the login page then after successfull login it takes you to the page where you add your post.
Thanks
Posted: Fri Sep 02, 2005 12:51 am
by feyd
storing last known url (or way to regenerate it) and/or view-state is what I've done in the past. View-state being often quite a bit more complicated.
Posted: Fri Sep 02, 2005 3:41 am
by Jim_Bo
Hi,
I have managed to sort out the redirection after login, but still havnt managed to carry the session across to another brower using:
Code: Select all
http://www.site.com/index.php?action=activate&id=$userid&code=$npassword&page=$page&PHPSESSID=$sid
I have checked the session id within the email etc etc and its 100% correct .. for what reasons would it not be working?
Im on shared hosting so I dont have access to temp files etc ..
Thanks
Posted: Fri Sep 02, 2005 7:43 am
by feyd
the session likely has been destroyed by that point if the originating browser was closed.
Posted: Fri Sep 02, 2005 9:37 am
by josh
So, to verify that the session is being destroyed, refer to my fist post, you can change the session save path to something within your access temporarily using session save path. If the session is being destroyed you will need to take the steps using a save handler like I outlined in my first post