CookieHandler::WriteObjectContent()


Definition

Converts a PHP object or variable to a storable string and sets it as cookie content.
Optional a cookie lifespan can be set when the cookie is written as it is done in SetValidity().

Important! It's recommended to use this method with care because third parties could be able to modify system objects.

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 WriteObjectContent ( $Object, [$Days = NULL, [$Hours = NULL, [$Minutes = NULL, [$Seconds = NULL]]]] )

Parameters

Exceptions

Example

class User
{
   public $Name = '';
   public $Age  = 0;
}
 
$NewUser = new User ();
$NewUser->Name = "Mr. Smith";
$NewUser->Age  = 20;
 
$Cookie = new CookieHandler ("Testcookie");
 
try 
{
   $Cookie->WriteObjectContent ($NewUser);
}
catch (CookieHandlerException $e)
{
   // [...]
}