note 104678 added to function.session-set-cookie-params

From: Date: Thu, 30 Jun 2011 08:20:36 +0000
Subject: note 104678 added to function.session-set-cookie-params
Groups: php.notes 
Request: Send a blank email to php-notes+get-181087@lists.php.net to get a copy of this message
Setting the domain for cookies in session_set_cookie_params() only affects the domain used for the session cookie which is set by PHP. All other cookies set by calling the function setcookie() either: i) Use the domain set explicitly in the call to setcookie() or ii) Don't set the domain at all on the cookie and so the browser assumes it's for the current domain. So to make all your cookies be available across all sub-domains of your site you need to do this: $currentCookieParams = session_get_cookie_params(); $rootDomain = '.mywebsite.com'; session_set_cookie_params( $currentCookieParams["lifetime"], $currentCookieParams["path"], $rootDomain, $currentCookieParams["secure"], $currentCookieParams["httponly"] ); session_name('mysessionname'); session_start(); setcookie($cookieName, $cookieValue, time() + 3600, '/', $rootDomain); ---- Server IP: 117.55.229.1 Probable Submitter: 59.167.234.48 ---- Manual Page -- http://www.php.net/manual/en/function.session-set-cookie-params.php Edit -- https://master.php.net/note/edit/104678 Del: integrated -- https://master.php.net/note/delete/104678/integrated Del: useless -- https://master.php.net/note/delete/104678/useless Del: bad code -- https://master.php.net/note/delete/104678/bad+code Del: spam -- https://master.php.net/note/delete/104678/spam Del: non-english -- https://master.php.net/note/delete/104678/non-english Del: in docs -- https://master.php.net/note/delete/104678/in+docs Del: other reasons-- https://master.php.net/note/delete/104678 Reject -- https://master.php.net/note/reject/104678 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181087) next »