Notes 12
Cookies and Sessions
- Cookie - small piece of information that scripts can store on a
client-side machine
- Set-Cookie: name=value; [expires=date;] [path=path;]
[domain=domain_name;] [secure;] [HttpOnly]
bool setcookie(string name [,string val [,int expire=0 [,string path
[,string domain [,int secure=false] [,int httponly=false] ]]]])
setcookie('mycookie','value');
- Session - session ID cookie stored on client-side machine,
server-side session variables are stored with relation to session ID
- 1) Start session 2) SET session vars 3) Use session vars
4) UNSET session vars and destroy session
session_start()
$_SESSION['myvar'] = 5;
if(isset($_SESSION['myvar'])){//session and var is set}
unset($_SESSION['myvar']);
or
$_SESSION = array();
session_destroy();
User Authentication (Form + Database)
Hashed Passwords