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

From: Date: Mon, 15 Mar 2010 08:56:12 +0000
Subject: note 96766 added to function.session-set-cookie-params
Groups: php.notes 
Request: Send a blank email to php-notes+get-167028@lists.php.net to get a copy of this message
Thanks for quintellarosa at yahoo dot com dot br that give me an idea to overcome session_set_cookie_params(). The code need little bit modification since first time (no session cookie created yet) $_COOKIE[SessionCookieName] does not have a value and thus the cookie not created properly. Here is the code I am using: <?php $SessionCookieName = 'sid'; $SessionCookieLifetime = 900; session_name($SessionCookieName); // Setting localhost in cookie domain will never work just let it empty for localhost and assign a host in server. $Domain = $_SERVER['HTTP_HOST']; if ($Domain=='localhost') $Domain = ''; session_start(); // set the $_COOKIE first if not defined. if (!isset($_COOKIE[$SessionCookieName]) || $_COOKIE[$SessionCookieName] == "") $_COOKIE[$SessionCookieName] = session_id(); // Now we are able to change lifetime, path, domain, secure and httponly. setcookie($SessionCookieName, $_COOKIE[$SessionCookieName], time() + $SessionCookieLifetime, '/', $Domain, false, true); ?> LaNN ---- Server IP: 78.110.173.36 Probable Submitter: 203.115.242.222 ---- Manual Page -- http://www.php.net/manual/en/function.session-set-cookie-params.php Edit -- https://master.php.net/note/edit/96766 Del: integrated -- https://master.php.net/note/delete/96766/integrated Del: useless -- https://master.php.net/note/delete/96766/useless Del: bad code -- https://master.php.net/note/delete/96766/bad+code Del: spam -- https://master.php.net/note/delete/96766/spam Del: non-english -- https://master.php.net/note/delete/96766/non-english Del: in docs -- https://master.php.net/note/delete/96766/in+docs Del: other reasons-- https://master.php.net/note/delete/96766 Reject -- https://master.php.net/note/reject/96766 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167028) next »