Jump to content

Sessions and sub domain


Simmo

Recommended Posts

Hi

 

I have written a server session on login in the main domain and am trying to read it when they are sent to their sub domain.  Unfortunately it won't read the session.  I have searched for a solution, which points to altering the php ini.

 

Is there another option that anyone knows about.

 

Thanks

Link to comment
Share on other sites

Hi

 

I have tried various snippets settings from searching  smilar to what you have said. I have also tried snippets of code in the htaccess but it didn't like that at all. Could you post one that you know works and tell me how it should be use e.g.  is it on each page you call the session.

 

I can't post the code I have tried because I have tried a few and didn't save them

 

Thanks

Link to comment
Share on other sites

You can only set php settings in a .htaccess file when php is running as an Apache Module AND your web host has permitted settings to be changed in a .htaccess file. You can only set php settings in a local php.ini when php is running as a CGI application AND your web host has configured your server to cause php to use a local php.ini (some server configurations require a local php.ini in each folder that you want the settings to affect.)

 

If both of those methods are not available, you can always set the session.cookie_domain setting in your script (before every session_start() statement), using either session_set_cookie_params or ini_set

 

Link to comment
Share on other sites

Thanks for reply

 

I may be way off and apologise for being hard work, but does this look about right:

 

ini_set('session.cookie_domain', '.subdmonain.maindomain.co.uk');

 

I have tried this before each session_start(); when creating the session and trying to read it, though it didn't work.

 

Thanks

Link to comment
Share on other sites

Hi

 

I can't understand why its not working.  I have two test scripts: swrite and sread

 

swrite is in the main root:

<?php

ini_set('session.cookie_domain', '.maindomain.co.uk');

session_start();

$_SESSION['test'] = "Write text";

?>

and sread is in the subdomain folder:

<?php

ini_set('session.cookie_domain', '.maindomain.co.uk');

session_start();

echo $_SESSION['test'];

?>

 

I have also tried removing the period before the main domain

 

Any advice would be appreciated

 

Thanks

Link to comment
Share on other sites

The only thing that code does (did you read it?) would be to report and display any php detected errors.

 

If it suddenly started working, you likely had an existing session id cookie set with values that did not work and you likely completely closed your browser so that you got a new session id cookie with the setting that does work.

Link to comment
Share on other sites

Hi

 

Mmmm.  I thought the E_ALL may have suppressed an error.(only guessing though)

 

Anyway. To test it I created a killsession.php :

<?php

ini_set('session.cookie_domain', '.booking-availability.co.uk');

session_start();

session_destroy();

?>

 

then ran the same scripts, only this time I did get an error on the sread.php:

 

Notice: Undefined index: test in /hom........

 

Line 7 : echo $_SESSION['test'];

 

I then opened a different browser (ff) and everything was fine.  So I guess It was not working because I was creating sessions to test it in different places.  I can't understand why my kill sessions script didn't work though?

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.