PHP独立.docx
《PHP独立.docx》由会员分享,可在线阅读,更多相关《PHP独立.docx(21页珍藏版)》请在冰豆网上搜索。
PHP独立
经济与管理学院
实训报告册
课程名称PHP编程
实训性质独立实训(集中)
学期
学生姓名
学号
专业班级
指导老师
实训项目:
1、文件上传
实训时间:
年月日节实训地点:
一、实训内容及目的
1、访问FTP服务器,下载AppServ软件包和EditPlus软件包,正确安装AppServ和EditPlus。
2、在EditPlus中正确配置服务器,确保在EditPlus中可以直接测试PHP代码。
3、编写PHP代码,测试文件上传代码,以上传jpg或者gif图片为例。
二、实训操作过程及实训结果(成果)
这里用move_uploade_file()函数实现文件上传,步骤如下:
(1)在register.php文件所在目录下创建一个目录(uploades)用于存放所有上传文件。
(2)修改register.php代码,将register.php程序修改为如下代码:
php
//若提交的表单数据超过post_max_size的配置,防止程序继续执行
if(empty($_POST)){
exit("您提交的表单数据超过post_max_size的配置!
");
}
echo"您填写的用户名为:
".$_POST['userName'];
echo"
";
echo"您注册的邮箱域名为:
".$_POST['domain'];
echo"
";
echo"您填写的登录密码为:
".$_POST['password'];
echo"
";
echo"您填写的确认密码为:
".$_POST['confirmPassword'];
echo"
";
echo"您填写的性别为:
".$_POST['sex'];
echo"
";
echo"您填写的个人爱好为:
";
foreach($_POST['interests']as$interest){
echo$interest."";
}
echo"
";
$myPicture=$_FILES['myPicture'];
$error=$myPicture['error'];
switch($error){
case0:
$myPictureName=$myPicture['name'];
echo"您的个人相片为:
".$myPictureName."
";
$myPictureTemp=$myPicture['tmp_name'];
$destination="uploads/".$myPictureName;
move_uploaded_file($myPictureTemp,$destination);
echo"文件上传成功!
";
break;
case1:
echo"上传的文件超过了php.ini中upload_max_filesize选项限制的值!
";
break;
case2:
echo"上传文件的大小超过了FORM表单MAX_FILE_SIZE选项指定的值!
";
break;
case3:
echo"文件只有部分被上传!
";
break;
case4:
echo"没有选择上传文件!
";
break;
}
echo"
";
echo"上传相片的文件大小不能超过:
".$_POST['MAX_FILE_SIZE']."字节";
echo"
";
echo"您填写的备注信息为:
".$_POST['remark'];
echo"
";
echo"您单击的提交按钮为:
";
echoisset($_POST['submit1'])?
"普通提交按钮":
"图像提交按钮";
?
>
单击“浏览”按钮选择上传的文件,单击“普通提交按钮”后可将浏览器端文件上传至WEB服务器目录中。
完成一个带有上传功能的“用户注册系统”。
三、总结体会
本次实训,我了解了了PHP上传照片及文件操作,通过编写代码,加深了对上传文件的代码的理解,了解了网站文件上传的基本知识,为以后复杂代码的编写打下了基础,本次实训我锻炼了自己的上机操作能力,为了熟练理解掌握,我还需要不练的进行练习。
四、评语及成绩评定
实训项目:
2、网页会话
实训时间:
年月日节实训地点:
一、实训内容及目的
1、访问FTP服务器,下载AppServ软件包和EditPlus软件包,正确安装AppServ和EditPlus。
2、在EditPlus中正确配置服务器,确保在EditPlus中可以直接测试PHP代码。
3、使用phpMyAdmin新建数据库
4、使用DremaweaverCS4与EditPlus,建立Session会话页面。
5、测试系统
二、实训操作过程及实训结果(成果)
1.新建add_session.php负责创建Session文件,并向文件写入信息。
代码如下:
php
session_start();
$_SESSION["user_name"]="admin";
$_SESSION["password"]=md5("admin");
echo"添加Sessions信息";
?
>
读取Session信息
2.创建read_session.php负责显示Session文件中的账户信息,代码如下:
php
session_start();
echo"读取Sessions信息";
echo"
";
echo"用户名:
";
if(isset($_SESSION["user_name"])){
echo$_SESSION["user_name"];
}else{
echo"暂无";
}
echo"
";
echo"密码:
";
if(isset($_SESSION["password"])){
echo$_SESSION["password"];
}else{
echo"暂无";
}
echo"
";
?
>
修改Session文件中的密码信息
删除Session文件中的密码信息
删除Session文件中的所有信息
销毁Session所有资源
3.创建delete_all_session.php程序负责删除Session文件中所有账户信息,代码如下:
php
session_start();
$_SESSION=array();
echo"删除Session所有信息";
?
>
重新读取Session文件账户信息
4.创建destroy_session.php程序负责删除Session文件中密码信息,并删除Session文件。
代码如下:
php
session_start();
session_unset();
if(isset($_COOKIE[session_name()])){
setcookie(session_name(),session_id(),time()-10);
}
session_destroy();
echo"销毁Session所有资源";
?
>
三、总结体会
通过新建数据库,建立Session会话页面以及测试系统的一系列操作,完成了Session的网页会话的编写。
通过对Session工作原理及作用的理解,再完成代码的编写,加深了理解,锻炼了上机操作能力。
四、评语及成绩评定
实训项目:
3、新闻系统
实训时间:
年月日节实训地点:
一、实训内容及目的
1、访问FTP服务器,下载AppServ软件包和EditPlus软件包,正确安装AppServ和EditPlus。
2、在EditPlus中正确配置服务器,确保在EditPlus中可以直接测试PHP代码。
3、组织网站文件结构
4、数据库的实施,news.sql语句的完成。
5、数据库连接函数database.php和init.php数据库初始化
6、新闻添加页面news_add.php,
7、新闻保存页面news_save.php,新闻列表页面news_list.php
8、新闻编辑页面news_edit.php,修改页面news_update.php和新闻详细信息页面news_detail.php
9、新闻评论保存页面review_save.php
10、分页函数的制作及news_list.php源代码的修改调试。
二、实训操作过程及实训结果(成果)
1.settable_type=InnoDB;
showvariableslike'table_type';
SETcharacter_set_client=gbk;
SETcharacter_set_connection=gbk;
SETcharacter_set_database=gbk;
SETcharacter_set_results=gbk;
SETcharacter_set_server=gbk;
SETcollation_connection=gbk_chinese_ci;
SETcollation_database=gbk_chinese_ci;
SETcollation_server=gbk_chinese_ci;
showvariableslike'character%';
showvariableslike'collation%';
createdatabasenews;
usenews;
createtablecategory(
category_idintauto_incrementprimarykey,
namechar(20)notnull
);
createtableusers(
user_idintauto_incrementprimarykey,
namechar(20)notnull,
passwordchar(32)
);
createtablenews(
news_idintauto_incrementprimarykey,
user_idint,
category_idint,
titlechar(100)notnull,
contenttext,
publish_timedatetime,
clickedint,
attachmentchar(100),
constraintFK_news_userforeignkey(user_id)referencesusers(user_id),
constraintFK_news_categoryforeignkey(category_id)referencescategory(category_id)
);
createtablereview(
review_idintauto_incrementprimarykey,
news_idint,
contenttext,
publish_timedatetime,
statechar(10),
ipchar(15),
constraintFK_review_newsforeignkey(news_id)referencesnews(news_id)
);
2.
php
$database_connection=null;
functionget_connection(){
$hostname="localhost";
$database="news";
$username="root";
$password="";
global$database_connection;
$database_connection=@mysql_connect($hostname,$username,$password)ordie(mysql_error());
mysql_query("setnames'gbk'");
@mysql_select_db($database,$database_connection)ordie(mysql_error());
}
functionclose_connection(){
global$database_connection;
if($database_connection){
mysql_close($database_connection)ordie(mysql_error());
}
}
?
>
3.
php
include_once("functions/database.php");
get_connection();
mysql_query("insertintocategoryvalues(null,'娱乐')");
mysql_query("insertintocategoryvalues(null,'财经')");
$password=md5(md5("admin"));
mysql_query("insertintousersvalues(null,'admin','$password')");
close_connection();
echo"成功添加初始化数据";
?
>
4.
php
include_once("functions/is_login.php");
session_start();
if(!
is_login()){
echo"请您登录系统后,再访问该页面!
";
return;
}
include_once("functions/file_system.php");
if(empty($_POST)){
$message="上传的文件超过了php.ini中post_max_size选项限制的值";
}else{
$user_id=$_SESSION["user_id"];
$category_id=$_POST["category_id"];
$title=$_POST["title"];
$content=$_POST["content"];
$currentDate=date("Y-m-dH:
i:
s");
$clicked=0;
$file_name=$_FILES["news_file"]["name"];
$message=upload($_FILES["news_file"],"uploads");
$sql="insertintonewsvalues(null,$user_id,$category_id,'$title','$content','$currentDate',$clicked,'$file_name')";
if($message=="文件上传成功!
"||$message=="没有选择上传附件!
"){
include_once("functions/database.php");
get_connection();
mysql_query($sql);
close_connection();
}
}
header("Location:
index.php?
url=news_list.php&message=$message");
?
>
5.
php
include_once("functions/is_login.php");
if(!
session_id()){//这里使用session_id()判断是否已经开启了Session
session_start();
}
if(!
is_login()){
echo"请您登录系统后,再访问该页面!
";
return;
}
include_once("functions/database.php");
$news_id=$_GET["news_id"];
get_connection();
$result_news=mysql_query("select*fromnewswherenews_id=$news_id");
$result_category=mysql_query("select*fromcategory");
close_connection();
$news=mysql_fetch_array($result_news);
?
>
标题:
phpecho$news['title']?
>">
内容:
php
include("fckeditor/fckeditor.php");//载入FCKeditor类文件
$oFCKeditor=newFCKeditor('content');//创建content在线编辑器,实例名为$oFCKeditor
$oFCKeditor->BasePath='fckeditor/';//设置FCKeditor实例的根目录
$oFCKeditor->Width=550;//设置FCKeditor实例的宽度
$oFCKeditor->Height=350;//设置FCKeditor实例的高度
$oFCKeditor->Value=$news['content'];//设置FCKeditor实例的内容
$oFCKeditor->ToolbarSet="Default";//设置FCKeditor实例的工具栏集合
$oFCKeditor->Config['EnterMode']='br';//设置FCKeditor实例的额外配置
$oFCKeditor->Create();//显示在线编辑器的HTML代码
?
>
类别:
php
while($category=mysql_fetch_array($result_category)){
?
>
phpecho$category['category_id'];?
>"
phpecho($news['category_id']==$category['category_id'])?
"selected":
""?
>>
phpecho$category['name'];?
>
php
}
?
>
phpecho$news_id?
>">
6.
php
include_once("functions/is_login.php");
session_start();
if(!
is_login()){
echo"请您登录系统后,再访问该页面!
";
return;
}
include_once("functions/file_system.php");
if(empty($_POST)){
$message="上传的文件超过了php.ini中post_max_size选项限制的值";
}else{
$user_id=$_SESSION["user_id"];
$category_id=$_POST["category_id"];
$title=$_POST["title"];
$content=$_POST["content"];
$currentDate=date("Y-m-dH:
i:
s");
$clicked=0;
$file_name=$_FILES["news_file"]["name"];
$message=upload($_FILES["news_file"],"uploads");
$sql="insertintonewsvalues(null,$user_id,$category_id,'$title','$content','$currentDate',$clicked,'$file_name')";
if($message=="文件上传成功!
"||$message=="没有选择上传附件!
"){
include_once("functions/database.php");
get_connection();
mysql_query($sql);
close_connection();
}
}
header("Location:
index.php?
url=news_list.php&message=$message");
?
>
7.
php
include_once("functions/database.php");
include_once("functions/page.php");
include_once("functions/is_login.php");
if(!
session_id()){//这里使用session_id()判断是否已经开启了Session
session_start();
}
//显示文件上传的状态信息
if(isset($_GET["message"])){
echo$_GET["message"]."
";
}
//构造查询所有新闻的SQL语句
$search_sql="select*fromnewsorder