PHP 学习1.4
1.session and cookie
示列:
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>title</title>
</head>
<body>
<?
define("SS","sulin");
echo constant("SS");
$_SESSION["USERID"]="LS";
echo $_SESSION["USERID"];
unset($_SESSION['USERID']);//unset() 函数用于释放指定的 session 变量
echo $_SESSION["USERID"];
session_destroy();//session_destroy() 函数彻底终结 session对象
?>
<?php
/*
isset
若变量不存在则返回 FALSE
若变量存在且其值为NULL,也返回 FALSE
若变量存在且值不为NULL,则返回 TURE
*/
if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
echo "Welcome guest!<br />";
?>
</body>
</html>
备注:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent
修正方法:session_start()调到程序的第一行