note 20911 deleted from function.setcookie by john

From: Date: Sat, 30 Nov 2002 16:34:20 +0000
Subject: note 20911 deleted from function.setcookie by john
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-40170@lists.php.net to get a copy of this message
/************************************************************ FUNCTION SEND_HTCOOKIE Author: Van Carney (van@Webfreshener.com) ©2000-2002 Webfreshener.com last rev: 4/21/02 3:56:47 AM HTTP Cookie generation routine takes variable number of args and writes cookie to header per the Netscape Cookies Spec This user function is written to mimic the built-in setcookie() function in PHP. This was done as problems were noticed with that function when writing cached cookies from within Object Scopes. PHP would not write a cached cookie when setcookie() was called inside an object. This function has been tested and workes quite nicely in multiple scopes. usage: send_htCookie(string varname (required),string varval,string expire, string path, string domain, bool 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)) { $COOKIE .= "; EXPIRES=$expire";} if (isset($domain)) { $COOKIE .= "; DOMAIN=$domain"; } if (isset($path)) { $COOKIE .= "; PATH=$path"; } if (isset($secure) && $secure>0) { $COOKIE .= "; SECURE"; } header($COOKIE); return true; }

« previous php.notes (#40170) next »