====== CookieHandler::WriteJsonContent() ====== ---- ===== Definition ===== Converts an array to a JSON string and sets it as cookie content. \\ e.g. An array like ''array ('a'=>1, 'b'=>2, 'c'=>3)'' is written als content string ''{"a":1,"b":2,"c":3}''. \\ Optional a cookie lifespan can be set when the cookie is written as it is done in [[libraries:cookiehandler:cookiehandlerclass:setvalidity|SetValidity()]]. **Important!** As a cookie is part of the HTTP header, the writing of a cookie has to be done before the first output is sent to the browser (even blanks etc.). void WriteJsonContent ( $JsonArray, [$Days = NULL, [$Hours = NULL, [$Minutes = NULL, [$Seconds = NULL]]]] ) ===== Parameters ===== * **$JsonArray** //Array// \\ Array that's data should be written as JSON content in the user's storage. * **$Days** //Int (optional)// \\ Validity of the cookie in days. * **$Hours** //Int (optional)// \\ Validity of the cookie in hours. * **$Minutes** //Int (optional)// \\ Validity of the cookie in minutes * **$Seconds** //Int (optional)// \\ Validity of the cookie in seconds ===== Exceptions ===== * **CookieHandlerException:EC_WRITEERROR** (103) \\ The cookie couldn't be written * **CookieHandlerException:EC_INVALIDNUMBER** (102) \\ One of the validity parameters is no valid number ===== Example ===== $Cookie = new CookieHandler ("Testcookie"); $UserArray = array ( "name" => "Mr. Smith", "age" => 20 ); try { $Cookie->WriteJsonContent ($UserArray); } catch (CookieHandlerException $e) { // [...] } ~~NOTOC~~