十天学会php之第七天
[b][color=#ff6600] [/color][/b][color=#000000][font=宋体][size=10.5pt]学习目的:学会[/size][/font]SESSION[font=宋体][size=10.5pt]的使用[/size][/font][/color]
/i$G'O3D/L\6~-` w&w"w
[color=#000000]SESSION[/color][color=#000000][font=宋体][size=10.5pt]的作用很多,最多用的就是站点内页面间变量传递。在页面开始我们要[/size][/font]session_start();[font=宋体][size=10.5pt]开启[/size][/font]SESSION[font=宋体][size=10.5pt];[/size][/font][/color]
[color=#000000][font=宋体][size=10.5pt]然后就可以使用[/size][/font]SESSION[font=宋体][size=10.5pt]变量了,比如说要赋值就是:[/size][/font]$_SESSION['item']="item1";[font=宋体][size=10.5pt]要得到值就是[/size][/font]$item1=$_SESSION['item'];[font=宋体][size=10.5pt],很简单吧。这里我们可能会使用到一些函数,比如说判断是不是某[/size][/font]SESSION[font=宋体][size=10.5pt]变量为空,可以这么写:[/size][/font]empty($_SESSION['inum'])[font=宋体][size=10.5pt]返回[/size][/font]true or false[font=宋体][size=10.5pt]。[/size][/font][/color]
[font=宋体][size=10.5pt][color=#000000]下面综合一下前面所说的我们来看一个登陆程序,判断用户名密码是否正确。[/color][/size][/font]
[font=宋体][size=10.5pt][color=#000000]登陆表单是这样:[/color][/size][/font][color=#000000]login.php2}g;TB$_lc
<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>7D7R |MZ [8t!\;e
<form action="checklogin.php" method="post"><td align="center" valign="middle"><table width="400" border="0" cellpadding="5" cellspacing="1" class="tablebg">
<tr class="tdbg">
<td colspan="2"><div align="center">Administrators Login</div></td>
</tr>
<tr class="tdbg">^)g'a*M*tuyY)A"h
<td><div align="center">Username</div></td>
<td><div align="center">
<input name="username" type="text" id="username">
</div></td>9W/^4_L5az/|6H
</tr>3B#\7\lO)i}C t@
<tr class="tdbg">
<td><div align="center">Password</div></td>
<td><div align="center">P_:s bi4d
<input name="password" type="password" id="password">
</div></td>w&Jh;x Ak
</tr>
<tr class="tdbg">&z!gO?U Kn
<td colspan="2"><div align="center">1K j4[b,[ q^/]
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Clear"> A[,]Z:wR]Z1U
</div></td>
</tr>:wmb Jv dE1Q$TK]
</table></td></form>
</tr>