rishibala143 Posted January 7, 2012 Share Posted January 7, 2012 Hi I am developing a e-commerce website. The user logs in and buy a product when he checkout the page will redirect to the payment gateway. After the payment is completed it will return back to my website. This is ok. But when it is returning back the session maintained in my website get lost. This happen only for the first time. If the user again logged in and checkout the process works good and the session is maintaining. Why does the session lost for first time. I used session_start() in all the pages.. I cannot find the solutions. Kindly help.. Regards P.Balakrishnan Quote Link to comment https://forums.phpfreaks.com/topic/254539-session-not-maintaining-for-the-first-time/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 7, 2012 Share Posted January 7, 2012 It's likely that the host-name/subdomain (www. vs no www.) in the URLs are changing back and forth (between having and not having the www. on them) and the session id cookie only matches the URL variation where it was set at and when you are redirecting around, including the return URL you tell your payment gateway to use, you finally end up going between pages that all have the same host-name (or lack thereof) in the URL. If this is the case, here are some things you can do to fix the problem - 1) You should set up a .htaccess redirect to force all URL's to goto a single variation of your domain, 2) You should be constant in your code and in the return URL you give/configure your payment gateway to use to always build links/redirects with the same variation of your domain, 3) You should set the session.cookie_domain setting to be .yourdomain.com (with the leading dot . ) to get the session id cookie to match all variations of your domain. Quote Link to comment https://forums.phpfreaks.com/topic/254539-session-not-maintaining-for-the-first-time/#findComment-1305263 Share on other sites More sharing options...
SergeiSS Posted January 7, 2012 Share Posted January 7, 2012 It's better to check your code. Show it here. Quote Link to comment https://forums.phpfreaks.com/topic/254539-session-not-maintaining-for-the-first-time/#findComment-1305336 Share on other sites More sharing options...
rishibala143 Posted January 9, 2012 Author Share Posted January 9, 2012 It's likely that the host-name/subdomain (www. vs no www.) in the URLs are changing back and forth (between having and not having the www. on them) and the session id cookie only matches the URL variation where it was set at and when you are redirecting around, including the return URL you tell your payment gateway to use, you finally end up going between pages that all have the same host-name (or lack thereof) in the URL. If this is the case, here are some things you can do to fix the problem - 1) You should set up a .htaccess redirect to force all URL's to goto a single variation of your domain, 2) You should be constant in your code and in the return URL you give/configure your payment gateway to use to always build links/redirects with the same variation of your domain, 3) You should set the session.cookie_domain setting to be .yourdomain.com (with the leading dot . ) to get the session id cookie to match all variations of your domain. Yes you are correct. The Problem is solved. Thanks for your help :) Regards P.Balakrishnan Quote Link to comment https://forums.phpfreaks.com/topic/254539-session-not-maintaining-for-the-first-time/#findComment-1305681 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.