- BASICS
- Quotes
- Constants
- Control Structures
- Reference
- Number Systems
- VARIABLES
- Definition
- Variable Variable
- Exists
- Type Casting
- OPERATORS
- Aritmetic
- Bitwise
- String
- Comparison
- Logical
- FUNCTION
- Definition
- Anonymous
- Reference
- Variable Arguments
- ARRAY
- Basics
- Operations
- Create
- Search
- Modify
- Sort
- Storage
- STRING
- String Basics
- String Compare
- String Search
- String Replace
- String Format
- String Regexp
- String Parse
- Formating
- Json
- STREAMS
- File Open
- Read File
- Read Csv
- File Contents
- Context
- Ob_start
- OOP
- Object Instantiation
- Class Constructor
- Interfaces, Abstract
- Resource Visibility
- Class Constants
- Namespaces
- HTTP
- Headers
- File Uploads
-
Cookies
- Sessions
Cookies
Allows your application to store a small text file on client Web browser. If you want to set cookie for another domain, it can not be done.
setcookie('hide_menu', '1'); // Set a cookie on the client
setcookie('hide_menu', '1', 3600); // expiration time - 1 hour
if ($_COOKIE['hide_menu'] == 1) {
echo 'Hide Menu';
}
Values
Cookies values must be scalar, not arrays. To delete a cookie, set time negative.
setcookie('hide_menu', array()); //expects parameter 2 to be string
setcookie("hide_menu", false, -3600);
You can create cookie arrays using the same array.
Keep in mind that the amount of storage available is severely limited, use sessions instead.
setcookie('test[0]', "foo");
setcookie('test[1]', "bar");
Arguments
You can set different cookie arguments.
setcookie('hide_menu', '1', 86400, '/path/', 'www.example.com', 1);
// where cookie will be accesible - path
// allowed domain
// the browser can only send cookie in case of HTTPS
// expiration time one day
Last update: 531 days ago