I am starting to study in PHP and I have problems with the application: I need to put information about the object in PHP for the cookie, and then get the cookie for the repeated object on another page. Does anyone have a solution to this problem?
The information I want to store in a cookie is just some information, preferably Customer, like background color, window size.
<?php
class Client {
private $id;
private $pSize;
private $color;
function __construct($id) {
$this->id = $id;
}
public function getPSize() {
return $this->pSize;
}
public function setPSize($pSize) {
$this->pSize = $pSize;
}
public function getColor() {
return $this->color;
}
public function setColor($color) {
$this->color = $color;
}
}
?>
On the index.php page, I have:
<?php
include_once 'Client.class.php';
$client = new Client(1);
$client->setColor("#000000");
$client->setPSize(200);
$StringClient = serialize($client);
$_COOKIE['PreferenceClient'] = $StringClient;
? >
On another page, I get inrofmation:
if(isset($_COOKIE['PreferenceClient'])){
$objClient = unserialize($_COOKIE['PreferenceClient']);
echo $objClient->getColor();
}
I solved the problem. Thanks to everyone who helped. before I tried to get cookie information without serialization Guys, this is my first post, I apologize if I did something wrong. Should I do something for you?