Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: www and no www

  1. #1
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts

    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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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

  • Users who have thanked Fou-Lu for this post:

    timgolding (04-25-2012)

  • #3
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.

  • Users who have thanked Fou-Lu for this post:

    timgolding (04-25-2012)

  • #5
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    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.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •