一、cookie
1.建立cookie,註:必須在發送其他任何信心之前從伺服器發送到用戶端,否則導致錯誤。
使用函數發送cookie: setcookie(name, value);
2.讀取cookie
eg:setcookie('user', 'trout');
$COOKIE['user'];
3.添加參數
set(name, value, expiration, path, domain, sesure, httponly);
參數簡介:
name鍵, value值,
expiration存在時間,
path和 domain限制在特定檔案夾或域中才存在,
sesure值1表必須使用安全連線,反之值0表不必要,
httponly限制對cookie的訪問,比如禁止Javascript對cookie的訪問。
4.刪除cookie
使用通首次設定cookie時相同的參數,不設定值。
eg:setcookie('user', 'larry');
刪除:setcookie('user', '');
編碼測試:ws.php:
setted!';}?> test Choose your preferences:
This is the foot of the document
二、session 1.session與cookie區別:
1>session將資訊儲存於伺服器,cookie儲存於用戶端
2>session儲存資訊量更大
3>session更安全
2.建立session,註:必須在向web發資訊之前調用
1>調用函數:session_start();
2>通過數組$_SESSION進行數值記錄:$_SESSION[' email '];
3.訪問session:
$_SESSION[' email '];
4.刪除session:session資料存在兩個地方,故從兩個地方刪除:
1>session_start()
2>unset($_SESSION);
3>session_destory(); //刪除伺服器上的
編碼測試:ws.php:
test The session content:' .$SESSION['name']."\n".$SESSION['time'].'';unset($_SESSION);session_destroy();print 'destroy()!';}else {print ' name or password is worry!
';}}else {print ' make sure you enter both name and password!
';}}else {print '';}?>This is the foot of the document