note 96766 deleted from function.session-set-cookie-params by danbrown
| From: | danbrown@php.net | Date: | Mon, 15 Mar 2010 13:48:49 +0000 |
| Subject: | note 96766 deleted from function.session-set-cookie-params by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167030@lists.php.net to get a copy of this message | ||
Note Submitter: nalzam1 at gmail dot com
----
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