8
I am using a function exactly the same name
xoops_setcookie() $cookie_list = array(
array("path"=>"/xoops", "domain"=>".domain.com"),
array("path"=>"/", "domain"=>"xoops.domain.com"),
array("path"=>"/","domain"=>".anotherdomain.com...")// this does not work yet
);
function xoops_setcookie()
{
$vars=array('name','value','expire', 'path','domain','secure');
for ($i=0;$i<func_num_args();$i++) {
${$vars[$i]}=func_get_arg($i);
}
if (!$name) { return false; }
if (!isset($expire) || ($expire < 0)) $expire = time();
global $cookie_list;
if(!is_array($cookie_list)) {
$path = isset($path)?$path:"/";
send_htCookie($name, $value, $expire, $path, $domain, $secure);
} else {
foreach($cookie_list as $cookie){
$_path = isset($path)?$path:$cookie["path"];
$_domain = isset($domain)?$domain:$cookie["domain"];
$rest = false;
$rest = send_htCookie($name, $value, $expire, $_path, $_domain, $secure);
}
}
}
function send_htCookie() {
$vars=array('varname','varval','expire', 'path','domain','secure');
for ($i=0;$i<func_num_args();$i++) {
${$vars[$i]}=func_get_arg($i);
}
if (!$varname) { return false; }
$COOKIE = "Set-Cookie: $varname=$varval";
if (isset($expire) && ($expire > 0)) {
$COOKIE .= "; EXPIRES=".
gmdate("D, d M Y H:i:s",$expire) .
" GMT";}
if (isset($domain)) { $COOKIE .= "; DOMAIN=$domain"; }
if (isset($path)) { $COOKIE .= "; PATH=$path"; }
if (isset($secure) && $secure>0) { $COOKIE .= "; SECURE"; }
header($COOKIE,false);
return true;
}