PHP Tutorial : Cookies and sessions

Hi,
Difference between php sessions and cookies is very simple : sessions will die after you will close the browser, but, cookies can be stored and reminded even after 1000 years, with the exception that user to not delete it manually from his browser tools and options.
Err, sessions and cookies are used in php to store informations, like variables but a little bit different.
With a session you pass something like if an user is logged into his account, etc. With a cookie you could store the username and password, etc.

<?php
//set a new php session
$_SESSION['loggedin'] = "no";
//or
$_SESSION['loggedin'] = "yes";
//here you set a cookie
setcookie("username", "someuser", "time()+72400");
//and print the cookie
print $_COOKIE['username'];
?>
This entry was posted in Basic PHP and tagged , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>