一天学会php(下)
SESSION的使用
SESSION的作用很多,最多用的就是站点内页面间变量传递。在页面开始我们要session_start();
开启SESSION;
然后就可以使用SESSION变量了,比如说要赋值就是:$_SESSION['item']="item1";要得到值就
是$item1=$_SESSION['item'];,很简单吧。这里我们可能会使用到一些函数,比如说判断是不是
某SESSION变量为空,可以这么写:empty($_SESSION['inum'])返回true or false。
下面综合一下前面所说的我们来看一个登陆程序,判断用户名密码是否正确。
登陆表单是这样:login.php
<table width="100%" height="100%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<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">
<td><div align="center">Username</div></td>
<td><div align="center">
<input name="username" type="text" id="username">
</div></td>
</tr>
<tr class="tdbg">
<td><div align="center">Password</div></td>
<td><div align="center">
<input name="password" type="password" id="password">
</div></td>
</tr>
<tr class="tdbg">
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Clear">
</div></td>
</tr>
</table></td></form>
</tr>
</table>
处理文件checklogin.php
<?
require_once('conn.php');
session_start();
$username=$_POST['username'];
$password=$_POST['password'];
$exec="select * from admin where username='".$username."'";
if($result=mysql_query($exec))
{
if($rs=mysql_fetch_object($result))
{
if($rs->password==$password)
{
$_SESSION['adminname']=$username;
header("locatio
相关文档:
/***************************by
garcon1986********************************/
<?php
// -> 是指对象的方法或者属性
class Cart{
public function add_item($a,$b){
echo $a+$b.'<br>';
}
}
//$cart = new Cart; 两句意义相同
$cart = new Cart();
$cart->add_item("10", 1);
// =& ......
/***************************by
garcon1986********************************/
<?php
// simple assgin the values
$arr1 = array(12 => 10, 'sjg' => 'yaya');
echo $arr1[12].'<br>'; // 10
echo $arr1['sjg']."<br>"; //yaya
echo "wo ai ni !<p> ......
/***************************by garcon1986************************************/
<?php
error_reporting(E_ALL ^ E_NOTICE);
//create database test
//create table php_radio(id int(10) NOT NULL AUTO_INCREMENT, name varchar(100), description varchar(1000), primary key(id));
//insert php_radio value ......
php关键词
php中用于文件包含的关键词有:include、include_once、require、require_once。一般来说,把include和require分在一组里,而include_once和require_once是一种改进完善形式。本文通过研究include和require的性质,兼顾include_once和require_once,获得php文件包含的基本知识和潜在 ......
1.php 数据类型:浮点型,字符串,整形,逻辑型
2.$a="test"; print($a); 在php.ini 中设置error_reporting=E_ALL 警告状态时,会有提示。此用于测试未定义的变量。可以使用isset()检测变量是否存在,unset清除变量(),常量定义define("a","test");定义的常量具有全局作用。define 无法定义对象的数据结构,不过可以先存储变量 ......