Carry session to new browser

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Carry session to new browser

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post 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
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post 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
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

PHP should be propagating the SID for you automatically
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

look at what $_SERVER has in it.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

that is the complete url :-P

what you want is the 'query string'

$query_string = $_SERVER[''QUERY_STRING'']

Edit: damn feyd's fast
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the session likely has been destroyed by that point if the originating browser was closed.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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
Post Reply