Can anyone tell me what is wrong with my code?
<?php
class MyCookie
{
private $expiration = 0;
private $path = "";
private $domain = "";
private $secure = false;
private $httponly = false;
private $names = array();
public function __construct($e, $p = "/temp/", $s = false, $h = false) {
$this->expiration = $e;
$this->path = $p;
$this->domain = '.' . $_SERVER["SERVER_NAME"];
$this->secure = $s;
$this->httponly = $h;
}
public function getDomain() {
return $this->domain;
}
public function write($name, $value) {
return setcookie($name, $value, time() + $this->expiration, $this->path, $this->domain, $this->secure, $this->httponly);
}
public function delete($name) {
return setcookie($name, $value, time() - $this->expiration, $this->path, $this->domain, $this->secure, $this->httponly);
}
public function read($name) {
return $_COOKIE[$name];
}
}
session_start();
$cookie = new MyCookie(3600 * 24 * 30);
$cookie->write('name', 'jun');
echo $cookie->read('name');
?>
Somehow the cookie is not registering or showing up.