feel free to keep it strictly simple...

set_cookie / delete_cookie

method "set_cookie"

Introduced with LEPTON v5, by calling the set_cookie methode, a cookie is created.
Per default, this created cookie also contains the (unsupported in pre PHP 7.3 versions) samesite attribute; without some browsers might ignore the cookie in the future.

Syntax:

LEPTON_session::set_cookie( $name,
                            $value,
                            $options = array(),
                            $mustExists = false,
                            $mergeDefault = true );

  • $name The name of the cookie
  • $value The value of the cookie
  • $options (Optional) An array containing none, some or all of the following attributes:
    • expires => time() + ( 3 * 3600)     // expires in 3 hours
    • path => "/"
    • domain => ""
    • secure => true/false    // true for https connections, false otherwise
    • httpsonly => true
    • samesite => "Lax"
  • $mustExists (Optional) A boolean true or false value. When set to true but cookie does not exists, it is not created. Therefore true means update only
  • $mergeDefault (Optional) A boolean true or false value. When set to true, the options array is set with the default values, but with overwritten attributes from input options.

Possible return values are:

  • true The cookie have been created successfully
  • false An error occured during cookie creation. Therefore the cookie has not been created
  • null The $mustExists flag has been passed as true but cookie does not exists

For a detailed description of the option attributes and their possible values please check:

Note: for all missing or empty attributes in the options array passed to the set_cookie method,
the defaults listed above are used, except you use as parameter #5 the value false.

To create a cookie, simply do:

LEPTON_session::set_cookie

Create a cookie

  1. // specify the cookies name
  2. $name = "myOwnCookie";
  3. // define a dedicated value
  4. $value = "";
  5. // define the attributes differ from the defaults
  6. $options = array(
  7. "expires" => time() + (3 * 3600) // expire in 3 hours
  8. );
  9. // create a cookie
  10. LEPTON_session::set_cookie( $name, $value, $options );

Listing 1.1 :: LEPTON_session::set_cookie

last edit: 03. Jul 2020 CEST 18:55:02

 

method "delete_cookie"

Also introduced with LEPTON v5, by calling the delete_cookie methode, an existing cookie is deleted.

LEPTON_session::delete_cookie

Delete a cookie

  1. // define the name of the cookie
  2. $name = "myOwnCookie";
  3. // delete session cookie and session itself
  4. LEPTON_session::delete_cookie( $name );

Listing 1.2 :: LEPTON_session::delete_cookie

last edit: 03. Jul 2020 CEST 18:55:32