setcookie

setcookie -- Send a cookie

Description

int setcookie ( string name [, string value [, int expire [, string path [, string domain [, int secure]]]]])

setcookie( ) defines a cookie to be sent along with the rest of the header information . Cookies must be sent before any other headers are sent ( this is a restriction of cookies , not PHP ) . This requires you to place calls to this function before any html or head tags .

You may also replace any argument with an empty string ( " " ) in order to skip that argument . The expire and secure arguments are integers and cannot be skipped with an empty string . Use a zero ( 0 ) instead . The expire argument is a regular Unix time integer as returned by the time( ) or mktime( ) functions . The secure indicates that the cookie should only be transmitted over a secure HTTPS connection .



דוגמה 1 . setcookie( ) send examples

 
setcookie

 
(

 
"TestCookie"

 
,

 
$value)

 
;

 
setcookie

 
("TestCookie"

 
,

 
$value,time()+3600)

 
;

 
/

 
*

 
expire

 
in

 
1

 
hour

 
*

 
/

 
setcookie

 
("TestCookie"

 
,

 
$value,time()+3600

 
,

 
"

 
/

 
~rasmus

 
/

 
"

 
,

 
".utoronto.ca"

 
,

 
1)

 
;





דוגמה 2 . setcookie( ) delete examples

 
/

 
/

 
set

 
the

 
expiration

 
date

 
to

 
one

 
hour

 
ago

 
setcookie

 
(

 
"TestCookie"

 
,

 
""

 
,

 
time(

 
)

 
-

 
3600)

 
;

 
setcookie

 
("TestCookie"

 
,

 
""

 
,

 
time(

 
)

 
-

 
3600

 
,

 
"

 
/

 
~rasmus

 
/

 
"

 
,

 
".utoronto.ca"

 
,

 
1)

 
;





 
echo

 
$TestCookie

 
;

 
echo

 
$HTTP_COOKIE_VARS["TestCookie"]

 
;





 
setcookie

 
(

 
"cookie[three]"

 
,

 
"cookiethree")

 
;

 
setcookie

 
("cookie[two]"

 
,

 
"cookietwo")

 
;

 
setcookie

 
("cookie[one]"

 
,

 
"cookieone")

 
;

 
if

 
(isset

 
($cookie)

 
)

 
{

 
while

 
(list

 
($name

 
,

 
$value

 
)

 
=

 
each

 
($cookie)

 
)

 
{

 
echo

 
"$name

 
==

 
$value

 
br

 
\n"

 
;

 
    }

 
}