1.独立完成课上演示部分功能 2. 完善后台功能 ①当前页码不能是超链接。当前页码字体加红。 ②加上“上一页”,“下一页”功能。如果是第一页“上一页”不能点,如果是最后一页 “下一页”不能点 ...
一:完成注册
index1
<?php session_start(); ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php if (isset($_SESSION['uid']) && $_SESSION['uid']!="") { echo "欢迎:" . $_SESSION['uname'] . "<a href='logout.php'>退出</a>"; } else { echo "未登录,<a href='register.php'>注册</a> "; echo "<a href='login.php'>登录</a>"; } ?> </body> </html>login
<?php session_start(); mysql_connect("localhost","root","123456"); mysql_select_db("lichao"); if (isset($_SESSION['uid']) && $_SESSION['uid']!="") { header("Location:index.php"); } if (isset($_POST['login'])) { $username = trim($_POST['username']); $password = trim($_POST['password']); $password = md5($password); $sql = "SELECT * FROM user WHERE username='$username' and password='$password'"; $result = mysql_query($sql); if ($result != false) { if (mysql_num_rows($result) > 0) { $user = mysql_fetch_assoc($result); $_SESSION['uid'] = $user['id']; $_SESSION['uname'] = $user['username']; echo "<script type='text/javascript'>"; echo "alert('登录成功!');"; echo "location.href='index1.php'"; echo "</script>"; } else { //用户名、密码错误 echo "用户名或密码错误!"; } } } ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="" method="post"> 用户名:<input type="text" value="" name="username" /> <br /> 密码:<input type="password" value="" name="password" /> <br /> <input type="submit" value="登录" name="login" /> </form> </body> </html>register
<?php session_start(); mysql_connect("localhost","root","123456"); mysql_select_db("lichao"); if (isset($_SESSION['uid']) && $_SESSION['uid']!="") { header("Location:index.php"); } if (isset($_POST['register'])) { $username = trim($_POST['username']); $password = trim($_POST['password']); $password = md5($password); if (isset($_FILES['headphoto'])) { $headphotoPath = "upload/".$_FILES['headphoto']['name']; move_uploaded_file($_FILES['headphoto']['tmp_name'], $headphotoPath); } $sql = "INSERT INTO user VALUES(null, '$username', '$password', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '$headphotoPath')"; $result = mysql_query($sql); if ($result) { $_SESSION['uid'] = mysql_insert_id(); $_SESSION['uname'] = $username; echo "<script type='text/javascript'>"; echo "alert('注册成功!');"; echo "location.href='index1.php'"; echo "</script>"; } } ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="" method="post" enctype="multipart/form-data"> 用户名:<input type="text" value="" name="username" /> <br /> 密码:<input type="password" value="" name="password" /> <br /> 头像:<input type="file" name="headphoto" /> <br /> <input type="submit" value="注册" name="register" /> </form> </body> </html>logout
<?php session_start(); $_SESSION = array(); session_destroy(); header("Location:index1.php");二:完成编辑和删除
index1
<?php
session_start();
mysql_connect("localhost","root","123456");
mysql_select_db("lichao");
if (!isset($_SESSION['adminid']) || $_SESSION['adminid'] == '') {
header("Location:login.php");
}
$sql = "select * from user";
$result = mysql_query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
table,td,th {
border:1px solid black;
border-collapse: collapse;
}
.headphoto {
width: 50px;
}
</style>
</head>
<body>
<table>
<tr>
<th>ID</th>
<th>用户名</th>
<th>头像</th>
<th>注册时间</th>
<th>上次登录时间</th>
<th>操作</th>
</tr>
<?php
while($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>{$row['id']}</td>";
echo "<td>{$row['username']}</td>";
echo "<td>";
if ($row['head_photo'] != "") {
echo "<img class='headphoto' src=../{$row['head_photo']} />";
}
echo "</td>";
echo "<td>{$row['resgister_time']}</td>";
echo "<td>{$row['last_login_time']}</td>";
echo "<td><a href='edit.php?id={$row['id']}'>编辑</a> <a href='delete.php?id={$row['id']}'>删除</a></td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
edit
<?php $id=$_GET['id']; mysql_connect("localhost","root","123456"); mysql_select_db("lichao"); if (isset($_POST['register'])) { $username = trim($_POST['username']); $password = trim($_POST['password']); $password = md5($password); if (isset($_FILES['headphoto'])) { $headphotoPath = "upload/".$_FILES['headphoto']['name']; move_uploaded_file($_FILES['headphoto']['tmp_name'], $headphotoPath); } $sql = "UPDATE user SET username='$username', password='$password' WHERE id='{$id}'"; $result = mysql_query($sql); if ($result) { echo "<script type='text/javascript'>"; echo "alert('更新成功!');"; echo "location.href='index1.php'"; echo "</script>"; } } ?> <html> <head> <title></title> </head> <body> <h1>请输入更新的数据</h1> <form action="" method="post" enctype="multipart/form-data"> 用户名:<input type="text" value="" name="username" /> <br /> 密码:<input type="password" value="" name="password" /> <br /> <input type="submit" value="更新" name="register" /> </form> </body> </html>delete
<?php $id=$_GET['id']; mysql_connect("localhost","root","123456"); mysql_select_db("lichao"); $sql="delete from user where id='{$id}'"; $result = mysql_query($sql); if ($result != false) { echo "<script type='text/javascript'>"; echo "alert('删除成功!');"; echo "location.href='index1.php'"; echo "</script>"; }
作业要求: 1.独立完成课上演示部分功能 2.增加后台管理员登陆功能 2.1 创建管理员信息表 2.2 实现管理员登陆 3.实现后台用户编辑功能 &nbs...
实现jQuery Ajax方式的用户注册页面 ❖ 用户注册信息包括:用户名、密码、确认密码 ❖ 用户数据使用文本文件存储
使用JSON方式自己设计一种定义数据: 1.图书列表(多项),每项包含:图书标题、作者(多人)、ISBN、出版日期、定价 2.职工考勤记录(多项),每项包含:员工工号、姓名、所属部门、考勤月、缺勤记录(日期,可能有多项也可能没有)
❖ 实现基于Session的用户登录有效期控制 ❖ 实现用户登录时,通过表单选项设置登录有效期( 1小时、 1天、 1周) 。 ❖ 提示:使用Session时,客户端Cookie存储SessionID,  ...
❖ 修改Demo2-6-18,使用Session完成用户登录、注销功能 ❖ 完善Demo2-6-18,实现用户登录有效期控制。实现用户登录时,通过表单选项设置登录有效期( 1小时、 1天、 1周)。
了解其他PHP操作文件的函数,并完成基本的文件管理器 ❖展示某目录下的所有文件及子目录,默认为当前程序文件所在目录 ❖ 列表中包括上级目录,点击能够返回上级目录 ❖ 点击子目录后,进入子目录,展示子目录的文件列表 ❖ 文件名称后具有删...
依据Demo2-6-8完善发表文章功能 ❖ 发表的文章以文件形式存储,格式规范同示例中的规范 ❖ 表单项包括 ❖ 标题 ❖ 文章内容 ❖ 发表时间:自动根据当前时间生成 ❖ ID值无需输入,依据现有文章ID值自动依次增加
echo "<meta charset="utf-8"/>"
$str = "敏感词A和B";
$arr = array("A","B");
echo "$str </br>";
echo str_replace($arr,"哔", $str);
?>
实现对二维数组排序 ❖ 对购物车商品表格实现:按数量,按单价分别降序/升序排序。 ❖ 查阅参考手中, usort( )函数的说明。
根据Email地址分别取得域名和用户名 ❖ 例:”services@gmail.com“ ❖ 分别取得”services”和”gmail.com“
时间截取,分别截取时间日期字符串的日期部分和时间部分 ❖ 例如:”2016-04-16 20:17:20“ ❖ 截取得到”2016-04-16“和”20:17:20“
依据文件路径字符串分别得出文件名和文件扩展名 ❖ 例如:”E:/PHP/WebServer/user_list.php“ ❖ 截取得到”user_list”和”php“
<!DOCTYPE html> <html> <head> <title>计算年龄</title> </head> <body> <?php function Age($burnYear,$burnMon,$burnDay){ $nowYear=date("Y"); $nowMonth=date("m"); $nowDay=date("d"); if(strval($nowMonth+$nowDay)<strval($burnMon+$burnDay)) { $age=$nowYear-$burnYear-1; return $age; } else if(strval($nowMonth+$nowDay)>strval($burnMon+$burnDay)) { $age=$nowYear-$burnYear; return $age; } } $burnYear=1995; $burnMon=11; $burnDay=25; $num=Age($burnYear,$burnMon,$burnDay); echo"年龄:"; echo"$num"; ?> </body> </html>
<!DOCTYPE html> <html> <head> </head> <body> <?php function getWeek($nowDate,$startDate) { $nowWeek=date("W",strtotime($nowDate)); $startWeek=date("W",strtotime($startDate)); $week=$nowWeek-$startWeek+1; return $week; } $nowDate="2016-3-3"; $startDate="2016-2-22"; $getWeek=getWeek($nowDate,$startDate); echo $getWeek; ?> </body> </html>
计算年龄 ❖ 定义函数,根据出生日期计算年龄(精确到生日) ❖ 参数1:出生年;参数2:出生月; 参数3,出生日 ❖ 返回年龄
获取当前教学周 ❖ 定义函数,计算得到当前时间的教学周次。 ❖ 参数1:要计算的日期; ❖ 参数2:某学期开始日期,默认为本学期开始时间( 2016-2-22) ❖ 返回教学周次