Forum Moderators: coopster

Message Too Old, No Replies

Sessions And Sub-domains

Please help...

         

omoutop

9:22 am on Jun 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi to all! I need your valuable help for one more time...

The story is the following, typical e-commerce web site with shopping cart, bank connection etc., except from the domain I also created some subdomains which are also a big part of the system, all authorization procedures and session variables are done in the domain, 3 variables are created and passed from page to page once the user is logged in successfully. HOWEVER, when the user goes to a subdomain the sessions are gone...but if he goes back to the domain by clicking a link the sessions are there again and he is logged in, i have never worked with session variables in a multi-subdomain environment before and I feel very frustrated...Why do session variables dissappear when i go to a subdomain of the site-portal...please help me, any suggestions will be appreciated.

Thank you in advance

coopster

1:12 pm on Jun 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You just need to know how cookies work (assuming you are using cookies). Have a look at the documentation for setcookie [php.net], particularly the domain parameter.

omoutop

1:22 pm on Jun 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thank you for your aswer, unfortunately i am not using cookies and i wouldnt like to turn to cookies for a varitey of reasons, i found a solution that hepled manyu programmers overcome this problem with sesison variables but it doesnt seeen to work for me

you can make your session cookies carry across all subdomains if you like. and yes, www is considered a subdomain.


PHP Code:
// note how i put a . before your domain name,
// it acts as a wildcard to the browser.
ini_set('session.cookie_domain', '.example.com');
session_start();

I dont know why and i am still seraching for a solution but havent found somtehitng that works...very sad, so much time spent and no solution, do you have any other suggestions? (Also tried with .htaccess but nothing)

[edited by: coopster at 2:41 pm (utc) on June 8, 2006]
[edit reason] generalized domain [/edit]

coopster

2:44 pm on Jun 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You contradict yourself here. You say you aren't using cookies but then the example you show is using cookies. If you aren't using cookies then you are passing the session id through the query string or in your form somehow.

I would assume you are indeed using cookies by the looks of things and the explanation of your problem. Although you aren't using the PHP setcookie() function you should know that sessions still indeed set cookies if you have your server configured as such.

henry0

7:39 pm on Jun 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In a similar case I used a "spaghetti code" solution
add an hidden field in your form to pass the session value
then where you need to maintain the session create a "dummy" file just for the purpose of passing a value and creating a "fresh session"
Done!

I told you this works but is a bad practice

you will be better of following Coopster's lead!

omoutop

8:32 am on Jun 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thank you both for your answers, I will try to find the solution and report back.