Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-25-2012, 03:37 PM   PM User | #1
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,466
Thanks: 90
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
www and no www

For some reason my sites session drops when a user moves from www.domain.com to domain.com. Is there a way to ensure that www and no www users use the same session data?
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 04-25-2012, 03:46 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,751
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Change your session.cookie_domain to .yoursite.com. Easiest to do with session_set_cookie_params. Check the doc and user examples here: http://ca2.php.net/manual/en/functio...kie-params.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
timgolding (04-25-2012)
Old 04-25-2012, 04:02 PM   PM User | #3
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,466
Thanks: 90
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
I did

PHP Code:
ini_set("session.cookie_domain"".domain.co.uk"); 
Seems to work now.... yipee, thanks

Edit:

I guess this code will stop the sessions working on my development server?

__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 04-25-2012, 04:36 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,751
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Yes it will. You could however use ini_set('session.cookie_domain', '.' . $_SERVER['SERVER_NAME']); and that looks like it should work. Cookies only have a meaning in an application that can use them, so this won't work on the CLI since $_SERVER won't be available, but its irrelevant since CLI cannot use cookie normally with session_start or setcookie; that would require the use of curl or another method to handle anyway.

Edit:
Perhaps a better approach would be to use a defined constant in a configuration script. This can be changed between the development and production using define('_MY_SITE', '.localhost') and define('_MY_SITE', '.site.com');. Then just use _MY_SITE in the ini_set.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
timgolding (04-25-2012)
Old 04-25-2012, 04:44 PM   PM User | #5
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,466
Thanks: 90
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
Good idea the domain on the development server will be 192.168.1.99. so should i use ini_set('session.cookie_domain', '.192.168.1.99'); ?
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 04-25-2012, 06:39 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,751
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by timgolding View Post
Good idea the domain on the development server will be 192.168.1.99. so should i use ini_set('session.cookie_domain', '.192.168.1.99'); ?
If you attach to it via http://192.168.1.99 and there is no map between localhost and this address, then use the address. If its mapped to localhost, I'd suggest using .localhost when you can.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
www

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:32 PM.


Advertisement
Log in to turn off these ads.