Cookies are a way for a server to store information on the user's computer.
A cookie is a small file that the server embeds on the hard drive of the user's computer (it is limited to about 4 KB of total data). Each time the same computer accesses a page with the same browser, it will send the cookie too.
setcookie(name, value, expire, path, domain, secure)"name" - The name of the cookie
<?php $value = 'I AM'; $one_hour = 3600; $one_week = 60*60*24*7; setcookie("cookie_name1", $value); // expire when the browser closes setcookie("cookie_name2", $value, time()+$one_hour); // expire in 1 hour setcookie("cookie_name3", $value, time()+$one_week, "/"); // expire in 1 hour (available within the entire web site) ?> <html> ...
<?php if (isset($_COOKIE['cookie_name'])) { // get and output the value of "cookie_name" $cookie_val = $_COOKIE['cookie_name']; echo $cookie_val; } else { echo 'The cookie: cookie_name is not set'; } // get and output all cookies for the current website $cookie_all = print_r($_COOKIE, true); echo $cookie_all; ?>
print_r($var) displays information about $var variable, but when TRUE is added, print_r($var, true) returns the information rather than print it, and can be transfered to a variable.
<?php setcookie("cookie_name", "", time()-3600); ?> <html> ...When deleting a cookie, if you set the "path" and "domain" in the creation cookie, use them again in the deletion cookie.
Cookies are not an indicated way to store information, the user can any time delete them or set its browser to not accept cookies.
<ul> <li>http://coursesweb.net/html/</li> <li>http://coursesweb.net/css/</li> </ul>
.some_class { display: list-item; }
var obj = { "courses": ["php", "javascript", "ajax"] }; var jsonstr = JSON.stringify(obj); alert(jsonstr); // {"courses":["php","javascript","ajax"]}
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>'; $dochtml = new DOMDocument(); $dochtml->loadHTML($strhtml); $elm = $dochtml->getElementById("dv1"); echo $elm->nodeValue; // CoursesWeb.net