![[计算机]PHP教程训练.doc_第1页](http://file.renrendoc.com/FileRoot1/2019-1/5/b3fc58b0-2c7f-42ec-8183-b6f2cb882ab8/b3fc58b0-2c7f-42ec-8183-b6f2cb882ab81.gif)
![[计算机]PHP教程训练.doc_第2页](http://file.renrendoc.com/FileRoot1/2019-1/5/b3fc58b0-2c7f-42ec-8183-b6f2cb882ab8/b3fc58b0-2c7f-42ec-8183-b6f2cb882ab82.gif)
![[计算机]PHP教程训练.doc_第3页](http://file.renrendoc.com/FileRoot1/2019-1/5/b3fc58b0-2c7f-42ec-8183-b6f2cb882ab8/b3fc58b0-2c7f-42ec-8183-b6f2cb882ab83.gif)
![[计算机]PHP教程训练.doc_第4页](http://file.renrendoc.com/FileRoot1/2019-1/5/b3fc58b0-2c7f-42ec-8183-b6f2cb882ab8/b3fc58b0-2c7f-42ec-8183-b6f2cb882ab84.gif)
![[计算机]PHP教程训练.doc_第5页](http://file.renrendoc.com/FileRoot1/2019-1/5/b3fc58b0-2c7f-42ec-8183-b6f2cb882ab8/b3fc58b0-2c7f-42ec-8183-b6f2cb882ab85.gif)
全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第1章 PHP概述国程序7-1文件名:setup.php程序7-2文件名:pageheader.html/产生留言板的主页面 /通过图片方式,显示“请你留言”4个字 写新留言 查看留言 搜索留言 返回首页 程序7-3文件名:write.php? require(setup.php);function ubbcode($Text) /无内容。 $Text=htmlspecialchars($Text);/对变量$Text中的字符串进行比对解析并取代 $Text=preg_replace(/t/is,$Text); $Text=preg_replace(/h1(.+?)/h1/is,1,$Text); $Text=preg_replace(/h2(.+?)/h2/is,1,$Text); $Text=preg_replace(/h3(.+?)/h3/is,1,$Text); $Text=preg_replace(/h4(.+?)/h4/is,1,$Text); $Text=preg_replace(/h5(.+?)/h5/is,1,$Text); $Text=preg_replace(/h6(.+?)/h6/is,1,$Text); $Text=preg_replace(/url(.+?)/url/is,1,$Text); $Text=preg_replace(/url=(.+?)(.*)/url/is,2,$Text); $Text=preg_replace(/img(.+?)/img/is,$Text); $Text=preg_replace(/b(.+?)/b/is,1,$Text); $Text=preg_replace(/email(.+?)/email/is,1,$Text); $Text=preg_replace(/i(.+?)/i/is,1,$Text); return $Text;$error=;/若用户点击命令按钮【写完了】,执行下面的代码,负责将留言信息写入数据表中if ($cmd=savepost)if( $txtName= | $txtContent= | $txtpwd=)$error= 请输入您的大名和留言、密码!;else/*若将php.ini中magic-quotes-gpc设置为on,系统会自动将“”转换为“”,同时MySQL还需要将“”转化为“”。*/$txtName=ubbcode(ereg_replace(,$txtName);$txtFrom=ereg_replace(,$txtFrom);$txtEmail=ereg_replace(,$txtEmail);$txtpwd=ereg_replace(,$txtpwd);$txtContent=ubbcode(ereg_replace(,$txtContent);$txtHomePage=ereg_replace(,$txtHomePage);$date=date(Y.-.m.-.d. .H.:.i.:.s);if ($ip=hideip)$addr=;else $addr= ip:.$REMOTE_ADDR; if ($txtFrom=)$txtFrom=无从奉告;$txtFrom=$txtFrom.$addr; /对数据库进行操作$sql=insert into guestbook (password,postdate,username,sex,location,email,homepage,content) values (;$sql=$sql.$txtpwd.,;$sql=$sql.$date.,.$txtName.,.$selSex.,.$txtFrom.,.$txtEmail.,.$txtHomePage.,;$sql=$sql.$txtContent.);$connect_id=mysql_connect($dbserver,$dbusername,$dbpassword);mysql_select_db($databasename);mysql_query($sql);mysql_close($connect_id);echo n;echo document.location.href=guestbook.phpn;echo n;exit;?/以下代码主要负责构造供用户填写的留言表单请您留言/检查用户是否填写密码function checkpassword()if (document.frmGstBook.txtpwd.value=)window.alert( 您没填写密码! n);document.frmGstBook.txtpwd.focus();document.frmGstBook.txtpwd.select();return false;elsereturn true; ? if ($error!=)echo 错误:.$error ;? 大名: 性别: 男 女 不告诉你 来自: E-Mail: 主页: 密 码: 留言: 隐藏IP 程序7-4文件名:search.php搜索请输入搜索关键字程序7-5文件名:guestbook.php?require(setup.php);function c_jandc_i($text)/对变量$text中的字符串,依据指定的规则解析并取代$text=ereg_replace(C_J,$text);/将换行字符转换成HTML的指令。$Text=nl2br($Text);return $text;function ubbcode($Text) /无内容 $Text=htmlspecialchars($Text); $Text=nl2br($Text); /对变量$Text中的字符串进行比对解析并取代 $Text=preg_replace(/t/is,$Text); $Text=preg_replace(/h1(.+?)/h1/is,1,$Text); $Text=preg_replace(/h2(.+?)/h2/is,1,$Text); $Text=preg_replace(/h3(.+?)/h3/is,1,$Text); $Text=preg_replace(/h4(.+?)/h4/is,1,$Text); $Text=preg_replace(/h5(.+?)/h5/is,1,$Text); $Text=preg_replace(/h6(.+?)/h6/is,1,$Text); $Text=preg_replace(/url(.+?)/url/is,1,$Text); $Text=preg_replace(/url=(.+?)(.*)/url/is,2,$Text); $Text=preg_replace(/img(.+?)/img/is,$Text); $Text=preg_replace(/b(.+?)/b/is,1,$Text); $Text=preg_replace(/email(.+?)/email/is,1,$Text);$Text=preg_replace(/i(.+?)/i/is,1,$Text); return $Text;?php/设置显示记录的页数if (! isset($page) $intPage=1;else$intPage=$page;$intRecordCount=0;$intPageCount=0;/进行数据库连接$connect_id=mysql_connect($dbserver,$dbusername,$dbpassword);if ($connect_id=false)echo 连接到.$dbserver.失败;if (mysql_select_db($databasename,$connect_id)/设置显示页面的标题,并从guestbook表中读取记录if (isset($key) & $key!=)/判断变量是否已配置$newkey=ereg_replace(,$key); $color=#9900FF; $result_id=mysql_query(select * from guestbook where (username like %.$newkey.%) or (content like %.$newkey.%) or (reply like %.$newkey.%) or (reply like %.$newkey.%) or (replyname like %.$newkey.%) or (location like %.$newkey.%) order by postdate desc);$title=搜索含有.$newkey.的留言;else $result_id=mysql_query(select * from guestbook order by postdate desc);$title=浏览留言;$color=#000000;/获取表中记录数,并保存在变量$intRecordCount中$intRecordCount=mysql_num_rows($result_id);if ($intRecordCount=0) /转向留言echo 还没有留言或搜索不到留言,请您留言; else/计算需要显示留言信息的页数,并定位显示页 $intPageCount=ceil($intRecordCount/$intPagesize); $intStartNum=($intPage-1)*$intPagesize+1; if ($intPage$intPageCount) $intPage=$intPageCount; if ($intPage=$intPageCount) $intEndNum=$intRecordCount-($intPage-1)*$intPagesize; else $intEndNum=$intPage*$intPagesize; ?/显示留言信息/对用户是否输入密码进行检查function checkpassword()if (document.frmGstBook.txtpwd.value=)window.alert(您没填写密码! n);document.frmGstBook.txtpwd.focus();document.frmGstBook.txtpwd.select();return false;elsereturn true; 请输入搜索关键字: ?if (isset($key) & $key!=) echo ;echo 下面的留言中包含有关键字:$newkey;echo 共.$intRecordCount.条 ; ?if (mysql_data_seek($result_id,$intStartNum-1) echo n; if ($intPageCount1) echo 分页: n; for ($i=1;$i=$intPageCount;$i+) if ($i=$intPage) echo $i. else echo.$i. echo n; echo n; for ($i=0;$i$intPagesize;$i+) if ($myarray=mysql_fetch_row($result_id) echo 第.$myarray11.条留言删除修改回复n; echo n; echo ubbcode($myarray5); echo n; echo n; echo 性别:; if (trim($myarray2)=女) echo .$myarray2. else if (trim($myarray2)=不告诉你) echo .$myarray2. else echo .$myarray2. if ( trim($myarray3) echo 邮箱: if (trim($myarray4) if (eregi(http:/)|(https:/)|(ftp:/)|(ftps:/),$myarray4) echo 主页:; else echo ; echo n;echo 留言人大名:; echo $myarray0; echo 时间:$myarray6; echo 来自:; echo $myarray7;echo n; if (trim($myarray8)!=) echo ; echo $myarray9:回复.c_jandc_i($myarray8); echo ; echo ; else break; /进行分页 if ($intPageCount1) echo 分页: n; for ($i=1;$i=$intPageCount;$i+) if ($i=$intPage) echo $i. else echo .$i. echo n; echo n mysql_free_result($result_id);else echo 连接到数据库.$databasename.失败;mysql_close($connect_id);? ? if ($error!=)echo 错了:.$error ;? 大名: 性 别: 男 女 不告诉你 来自: E-Mail: 主页: 密 码: 留言: 隐藏IP 程序7-6文件名:deleormodi.php?require(setup.php);$error=;mysql_select_db($databasename);if (isset($postid) $result_id=mysql_query(select * from guestbook where postid=.$postid,$connect_id); if ($result_id=false) $error=没有该记录!; else $myarray=mysql_fetch_row($result_id); $connect_id=mysql_connect($dbserver,$dbusername,$dbpassword);mysql_free_result($result_id);mysql_close($connect_id);if ($cmdOk)/删除留言if ($deleormodi=dele) if ($password!=$adminpassword ) $error=口令不符!只有管理员才可以删除留言;else mysql_query(delete from guestbook where postid=.$postid,$connect_id);echo n;echo window.alert(留言已被删除);echo document.location.href=guestbook.phpn;echo n;exit; /修改留言 if ($deleormodi=modi) /$modipassword为超级用户口令,可更改任何人留言 if ($password=$myarray1 | $password=$modipassword) $connect_id=mysql_connect(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 华为公司激励机制对代理风险的影响研究
- 华晨宝马汽车有限公司薪酬制度问题研究
- 【《高职院校劳动课对学生自身素养提升实践研究》5900字(论文)】
- 服装尺码标准制定合同
- 石油购销合同(标准版)
- 数据驱动的录取决策-洞察及研究
- 对象软件的自动化安全测试框架-洞察及研究
- 2025年PA9T合作协议书
- 个性化系统设计-洞察及研究
- 深海热液生物多样性-第3篇-洞察及研究
- 2025年海关关务测试题及答案
- (正式版)DB3302∕T 1180-2025 《高速公路建设韧性指标体系》
- 2025年FSC认证原材料采购合同范本
- 2025年8月广东深圳市光明区住房和建设局招聘一般专干5人备考练习题库及答案解析
- 《煤矿安全规程(2025)》防治水新旧条文对照
- 语言哲学概况课件
- GB 16807-2025防火膨胀密封件
- 麻醉医生进修汇报课件
- 2025年国企审计笔试题及答案
- 开学第一课+课件-2025-2026学年人教版(2024)七年级英语上册
- 医院医疗收费培训课件
评论
0/150
提交评论