note 57773 added to function.setcookie

From: Date: Thu, 13 Oct 2005 19:59:45 +0000
Subject: note 57773 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-96977@lists.php.net to get a copy of this message
If you want to secure your cookies with the HttpOnly attribute (only supported by IE6. see http://msdn.microsoft.com/workshop/author/dhtml/httponly_cookies.asp ) you could create your own setcookie function by using the following function: <?php function mgk_setcookie($sName,$sValue,$iExpire=false, $sPath="",$sDomain="",$bSecure=false,$bHttpOnly=true) { $sHeader = "Set-Cookie: $sName=$sValue"; if ($sPath) { // optional $sHeader .= "; Path=$sPath"; } if ($iExpire !==false || $iExpire !== 0 ) { // 0 check because of php setcookie function which // isn't entirely compattible with the rfc. $sHeader .= "; Max-Age=$iExpire"; } if ($sPath) { // optional $sHeader .= "; Path=$sPath"; } if ($sDomain) { // optional $sHeader .= "; Domain=$sDomain"; } if ($bSecure) { // optional $sHeader .= "; Secure"; } if ($bHttpOnly) { // IE6 only attribure $sHeader .= "; HttpOnly"; } $sHeader .= "; Version=\"1\""; // not sure if i use the right version header($sHeader); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.setcookie.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57773 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57773&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57773&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57773&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57773&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57773&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57773&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57773&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57773&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96977) next »