note 57773 deleted from function.setcookie by bjori
| From: | bjori@php.net | Date: | Mon, 08 Jan 2007 10:47:53 +0000 |
| Subject: | note 57773 deleted from function.setcookie by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-121428@lists.php.net to get a copy of this message | ||
Note Submitter: marc at NOSPAM dot grootkoerkamp dot net
----
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);
}
?>