Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use my Cookie class properly
    primarykey
    data
    text
    <p>I just started with OOP programming in PHP and I have made a cookie class. </p> <p>With doing that i have got a few questions unanswered </p> <ul> <li><p>is my class correct?</p></li> <li><p>how do I use it properly in my page? ( lets think i want to see how many times the visitor visited my website before and output the result for the user )</p></li> </ul> <p>I already tested it after loging in and using this code: </p> <pre><code>$cookie = new Cookie(); $cookie-&gt;store(); print_r($_COOKIE); </code></pre> <p>(I had a result thrown back but I don't know if its the good result) Bellow you can find my Cookie class. </p> <pre><code>&lt;?php class Cookie { /* cookie $id */ private $id = false; /* cookie life $time */ private $time = false; /* cookie $domain */ private $domain = false; /* cookie $path */ private $path = false; /* cookie $secure (true is https only) */ private $secure = false; public function __construct ($id, $time = 3600, $path = false, $domain = false, $secure = false) { $this-&gt;id = $id; $this-&gt;time = $time; $this-&gt;path = $path; $this-&gt;domain = $domain; $this-&gt;secure = $secure; } public function store() { foreach ($this-&gt;parameters as $parameter =&gt; $validator) { setcookie($this-&gt;id . "[" . $parameter . "]", $validator-&gt;getValue(), time() + $this-&gt;time, $this-&gt;path, $this-&gt;domain, $this-&gt;secure, true); } } public function restore() { if (isset($_COOKIE[$this-&gt;id])) { foreach ($_COOKIE[$this-&gt;id] as $parameter =&gt; $value) { $this-&gt;{$parameter} = $value; } } } public function destroy() { $this-&gt;time = -1; } } ?&gt; </code></pre> <p>I hope someone can give me a good example! thanks for the help in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload