⑴ 解釋分析php留言板代碼 急!好的 詳細的加高分!
呼呼,給你幾乎每一句都注釋了
<form action="#" method="post"
enctype="multipart/form-data">
name<input name=name >sex<input name=sex >age<input name=age >QQ<input name=qq >
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
<!--以上為留言板的留言表單-->
<?php
$host="localhost";
$user="root";
$password="";
$db="testdb";
$con=@mysql_connect($host,$user,$password); //不報錯創建與mysql資料庫伺服器的連接
if(!mysql_select_db($db)){ //選擇伺服器資料庫
echo "沒有相應資料庫,正在給你創鍵"; //如果資料庫不存在
mysql_query("CREATE DATABASE `testdb` DEFAULT CHARACTER SET gb2312 COLLATE gb2312_chinese_ci;"); //創建一個名為textdb的資料庫,使用gb2312字元集
mysql_query("CREATE TABLE `testdb`.`book` ( //一下為在textdb下創建book數據表
`name` VARCHAR( 20 ) NOT NULL , //表列name,為20字元以內的非空字元串
`sex` VARCHAR( 3 ) NOT NULL , //表列sex,為3字元以內的非空字元串
`age` INT( 3 ) NOT NULL , //表列age,為3位以內的整數
`time` VARCHAR( 20 ) NOT NULL , //表列time,為20字元以內的非空字元串
`qq` VARCHAR( 15 ) NOT NULL , //表列qq,為15字元以內的非空字元串
`url` VARCHAR( 30 ) NOT NULL , //表列url,為30字元以內的非空字元串
PRIMARY KEY ( `name` ) //創建關鍵索引name
) ENGINE = MYISAM;"); //使用MYISAM資料庫系統
echo "成功創建!";
}
if(!file_exists("up")) //如果up文件夾不存在
{
mkdir("up",0777); //創建文件夾up,為全體可讀寫執行
@chmod("up",0777); //不報錯改變文件夾up為全體可讀寫執行
}
$name=split("\.",$_FILES["file"]["name"]); //用「.」分割上傳的文件名字,返回一個數組
$counter=count($name)-1; //給$counter賦值$name數組的個數減一
$pre=$name[count($name)-1]; //給$pre賦值$name數組的最後一位(也就是文件擴展名,不含「.」)
$dastr=date("YmdHis"); //給$dastr賦值當前時間(格式為:年月日時分秒)
if (file_exists("up/" . $_FILES["file"]["name"])) //如果up文件夾中有與上傳的文件重名的文件
{
echo $_FILES["file"]["name"] . " already exists. "; //輸出文件已存在
}
else //否則
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"up/" . $dastr.'.'.$pre); //將上傳的文件從臨時緩存移動到up文件夾當中並改名為「日期.擴展名」
}
$name=$_POST['name']; //給$name賦值為表單中name輸入框的內容
$age=$_POST['age']; //給$age賦值為表單中age輸入框的內容
$sex=$_POST['sex']; //給$sex賦值為表單中sex輸入框的內容
$qq=$_POST['qq']; //給$qq賦值為表單中qq輸入框的內容
$url="up/" . $dastr.'.'.$pre; //給$url賦值為上傳文件的地址
$time=date("Y-m-d H:i:s"); //給$time賦值為當前時間(格式:年-月-日 時:分:秒)
mysql_query("set names gb2312"); //設置字元集,解決中文亂碼問題
mysql_select_db($db); //選擇資料庫
$exec="insert into book (name,age,sex,qq,time,url) values ('$name','$age','$sex','$qq','$time','$url')";
//給$exec賦值向book表中添加數據的命令字元串
if($name!=''){ //如果$name不是空
$result=mysql_query($exec); //執行$exec的命令
}
$sql="select * from book"; //給$sql賦值選取book當中的所有列和行的命令的字元串
$result=mysql_query($sql); //執行$sql語句,返回結果
while($rs=mysql_fetch_object($result)) //遍歷所有結果(循環直到所有$result當中的結果都以輸出)
{
echo "<div class=result><ul><li>用戶名:".$rs->name."</li>\n"; //一下為輸出留言內容
echo "<li>年領:".$rs->age."</li>\n";
echo "<li>年領:".$rs->sex."</li>\n";
echo "<li>QQ:".$rs->qq."</li>\n";
echo "<li>頭像: <img src=".$rs->url." /></li>\n";
echo "<li>留言時間:".$rs->time."</li></ul></div>\n";
}
mysql_close(); //關閉與數據服務間的連接
?>
⑵ 新手剛學ThinkPHP 網上找的都是3.1版本的,改動很大。ThinkPHP3.2 留言板源碼 求學習
程序都一樣的。。 改的也是一部分,多練練,就可以啦。
⑶ 急求一個PHP的簡單的留言板,輸入臨時名字 然後輸入留言提交就可以顯示在頁面的
<?php
include 'conn.php'
$action = $_GET['action'];
$user=str_replace(" ","",$_POST[textfield]);
if($_POST['Submit2']){
if(!empty($_POST[textfield])){
$user=str_replace(" ","",$_POST[textfield]);
$password=str_replace(" ","",$_POST[textfield2]);
$user1=md5($user);
$password1=md5($password);
function userlogin($user1)
{
global $manager;
$sql="select * from $manager where user='$user1'";
//$sql="insert into manager (user,password) values ('$user','$password');";//用於插入需要的管理員用戶信息
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
return $row;
}
$row=userlogin($user1);
if($row){
$ps=$password1==$row[password];
}else{
$ps=FALSE;
// echo "<script type="text/javascript">alert("用戶名錯誤")</script>";
}
if($ps){
$_SESSION[uid]=$user;
$_SESSION[upass]=$row[password];
header("Location:index.html");
}else{
$b=FALSE;
echo "<script type="text/javascript">alert("用戶名或者密碼錯誤")</script>";
echo '<script language="JavaScript">window.location.href="login.html";</script>'
}
}else{
echo "<script type="text/javascript">alert("用戶名不能為空格")</script>";
echo '<script language="JavaScript">window.location.href="login.html";</script>'
}
}
?>
以上是userlogin.php文件,其中引用的conn.php文件代碼如下:
其中資料庫自己建一個,注冊頁面大體也相同,你理解了這個,就自己能寫注冊頁面了
<?php
@header('Content-Type: text/html; charset=utf-8');
@session_start();
$conn = @ mysql_connect("127.0.0.1", "zznt", "19880210") or die("資料庫連接錯誤");
mysql_select_db("zznt", $conn);
//mysql_query("set NAMES 'utf8'");
//mysql_query("set character_set_client=utf8");
//mysql_query("set character_set_results=utf8");
mysql_query("set NAMES 'utf8'");
mysql_query("set character_set_client=utf8");
mysql_query("set character_set_results=utf8");
//$content=str_replace("'","鈥?,$content);
//htmlspecialchars();
?>
⑷ 求php語言編寫的留言板源碼!!!!!!!!!
這是一個簡單的留言本,目前還沒有後台管理程序。如果哪位高手能補上,那就太好了。
演示在http://www.ideawu.net/person/liuyan
留言保存在message.txt文件中,留言的格式為:date<$>ip<$>name<$>content
"<$>"為分隔符號
注意:源碼文件和message.txt文件必須以gbk格式保存。如果你不知道如何保存文件為gbk格式,請咨詢你的文本編輯器軟體提供商。
/****************************************
* 本代碼可以用作任何用途,但是與作者無關。
* 也就是,你使用本代碼獲取收益或者因此受
* 到損害,後果與作者無關。
****************************************/
file: index.php
代碼:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>留言板</title>
<link rel="stylesheet" href="../msg.css" type="text/css">
</head>
<body>
<br><B><FONT COLOR="#0000FF">圖片留言板</FONT></B>
<center>
<table width="800" border="1" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all">
<tr><td style="border-right-style: none">
<form method="post" action="savemsg.php" style="font-size: 13px">
姓名:<br><input type="text" name="guest_name" maxlength=32 size=32><br>
留言:(字數:<font color="#0000FF"><span id=sNum>0</span></font>/256)<br>
<textarea class="textForm" name="guest_msg" cols="64" rows="8" onkeyup="sNum.innerHTML=this.value.length"></textarea><br>
<input class="button" type="submit" name="submit" value="發表留言">
<input class="button" type="reset" value="重置" name="reset">
</form>
</td></tr>
</table>
<?php
include("showmsg.php");
if(!empty($_GET['p'])){
$num=$_GET['p'];
showpage($num);
}else showpage(1);
?>
</center>
</body>
</html>
file: showmsg.php
代碼:
<?php
function showpage($p)
{ ?>
<table width="800" border="0" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all;font-size:12px;">
<tr><td>
<p style="line-height: 100%; margin-top: 1; margin-bottom: 1" align="left">
<?php
$perPage=7; //每頁顯示留言數目
$num=$p;
if($num<1) $num=1;
$prev=$num-1;
$next=$num+1;
$page=$num-1; //當前頁碼
$fname="message.txt"; //存儲留言的文件
$all_msg=file($fname); //將留言讀入數組
$line_count=count($all_msg);
$page_count=ceil($line_count/$perPage);
if($prev>0)
echo "<a href=index.php?p=$prev>上一頁</a>";
else
echo "上一頁";
if($line_count>($next-1)*$perPage)
echo "<a href=index.php?p=$next>下一頁</a>";
else
echo "下一頁";
echo "當前第 ".$num." 頁,共有".$page_count."頁,".$line_count."條留言。";
?>
</p></td></tr>
</table>
<table width="800" border="1" bordercolor="#88CCEE" cellpadding="3" cellspacing="0" style="border-collapse:collapse; font-size:12px; word-break:normal; table-layout:fixed;">
<tr height="18" bgcolor="#5FBEF8"><td width="20%">
<b>留言時間/留言者</b></td><td width="86%"><b>留言內容</b>
</td></tr>
<?php
//顯示留言
$bg1="#FBF9F9"; $bg2="#E9EFF4";$bg=$bg2;
for($n=$line_count-1-$page*$perPage;$line_count-1-$page*$perPage-$n<$perPage;$n--){
$bg=($bg==$bg1)? $bg2:$bg1; //變換背景顏色
if(!empty($all_msg[$n])){
list($date,$ip,$name,$msg)=explode("<$>",$all_msg[$n],4); //獲取留言內容
echo "<tr bgcolor=$bg>";
echo "<td width=14%>".$date."<br><b>".$name."</b></td>";
echo "<td width=86%>".$msg."</td>";
echo "</tr>";
}
}
?>
</table>
<table width="800" border="0" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all;font-size:12px">
<tr><td>
<p style="line-height: 100%; margin-top: 2; margin-bottom: 2" align="left">
<?php
if($prev>0)
echo "<a href=index.php?p=$prev>上一頁</a>";
else
echo "上一頁";
if($line_count>($next-1)*$perPage)
echo "<a href=index.php?p=$next>下一頁</a>";
else
echo "下一頁";
echo "當前第 ".$num." 頁,共有".$page_count."頁,".$line_count."條留言。";
?>
</p></td></tr>
</table>
<?php } ?>
file: savemsg.php
代碼:
<?php
$MSG_MAX_LEN=512; //留言最大長度
if (getenv("HTTP_CLIENT_IP"))
$ip= getenv("HTTP_CLIENT_IP");
elseif (getenv("HTTP_X_FORWARDED_FOR"))
$ip= getenv("HTTP_X_FORWARDED_FOR");
else
$ip= getenv("REMOTE_ADDR");
//獲取IP地址結束
$date=date("Y年m月d日 H:i:s",time());
if(empty($_POST['guest_name']))
die("請填你的名字。<a href=index.php>Refresh</a>");
if(empty($_POST['guest_msg']))
die("請填寫留言內容再提交。<a href=index.php>Refresh</a>");
$guest_name=strip_tags($_POST['guest_name']);
$guest_msg=substr($_POST['guest_msg'],0,$MSG_MAX_LEN);
//write message to file
//make the message be a line when stored
$guest_msg = str_replace( "\r\n", "\n", $guest_msg);
$guest_msg = str_replace( "\r", "\n", $guest_msg);
$guest_msg = str_replace(" "," ",$guest_msg);
$guest_msg = str_replace(">",">",$guest_msg);
$guest_msg = str_replace("<","<",$guest_msg);
$guest_msg = str_replace("\'","'",$guest_msg);
$guest_msg = nl2br($guest_msg);
//保存留言,以追加的形式
$fname="message.txt";
$fp=fopen($fname,"a+");
fwrite($fp,$date."<$>".$ip."<$>".$guest_name."<$>".$guest_msg."\n");
fclose($fp);
echo "<meta http-equiv='refresh' content='0;url=index.php'>";
?>
用於顯示效果的樣式表文件
file: msg.css
代碼:
A:link {
color: #0033FF;
text-decoration: none;
}
A:visited {
color: #0033FF;
text-decoration: none;
}
A:hover {
color: #30A300;
text-decoration: underline;
}
A:active {
color: #0036A9;
text-decoration: none;
}
BODY{
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 12px;
background: #FBF9F9;
}
TABLE{
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 12px;
border-collapse: collapse;
table-layout: fixed;
margin: 0px;
}
⑸ 求php語言編寫的留言板源碼!!!!!!!!!
這是一個簡單的留言本,目前還沒有後台管理程序。如果哪位高手能補上,那就太好了。
演示在
http://www.ideawu.net/person/liuyan
留言保存在message.txt文件中,留言的格式為:date<$>ip<$>name<$>content
"<$>"為分隔符號
注意:源碼文件和message.txt文件必須以gbk格式保存。如果你不知道如何保存文件為gbk格式,請咨詢你的文本編輯器軟體提供商。
/****************************************
*
本代碼可以用作任何用途,但是與作者無關。
*
也就是,你使用本代碼獲取收益或者因此受
*
到損害,後果與作者無關。
****************************************/
file:
index.php
代碼:
留言板
<b>
圖片留言板</b>
<table
width="800"
border="1"
bordercolor="#88CCEE"
cellspacing="0"
cellpadding="4">
<tr><td>
</td></tr>
</table>
file:
showmsg.php
代碼:
&l
⑹ 留言板PHP和mysql源碼
保存可以用txt或者mysql方式保存。如果你是剛學習可以用txt,
採用post方式提交後用$_POST['content']獲取到內容後用fwrite按格式寫到一個文件里,可以一行一個,讀取的時候用fgets讀取每行的內容,然後調用變數顯示到標簽里
<?php
if(isset($_POST['content'])){
$fp=fopen('talk.txt','w+');
fwrite($fp,$_POST['content']." ");
fclose($fp);
exit("提交成功");
}else{
echo'<formmethod="post"><textarearows="3"name="content"placeholder="請輸入內容"></textarea><br/><inputtype="submit"value="留言"/></form>';
$fp=@fopen("/tmp/inputfile.txt","r");
if($fp){
while(!feof($fp)){
$buffer=fgets($fp);
echo$buffer."<br>";//顯示每行內容
}
fclose($fp);
}else{
echo"打開文件失敗或者文件不存在";
}
}
?>
純手打,請採納
⑺ 本人PHP新手. 需要PHP源碼. ................~~~~~~~~~
PHP是C語言系列語言~~是網頁動態語言~~基礎的看完了~~如果你依然不懂得如何製作~~只能說明你還是沒有完全的看懂~~PHP的動態主要就在於一個反饋~~用戶與伺服器之間的反饋~~反饋的方式有POST與GET兩種~~記錄傳遞信息的有COOKIE與SESSION兩種~~這兩點如果看懂了~~其他的就和C區別不是很大了~~
如果你需要HTML與PHP混合編寫~~可以考慮在html語句中添加PHP~~例如:<a href="<?php echo "#"; ?>"></a>的方式~~也可以在PHP中添加HTML,例如<?php echo "<a href=\"#\">"; ?>。希望對你有所幫助~~
⑻ 誰有好用的PHP源碼留言簿
請到下面地址下載:
http://down.chinaz.com/soft/3337.htm
⑼ 最簡單php留言板源碼。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
</head>
<body>
<BR><BR>
<center><a href="admin_login.htm" target="_blank">留言管理</a> </center><BR><BR>
<br><br><br>
<form method="post" >
<p>姓名:
<input type="text" name="user_name" size="20">
</p>
<p><br>
電話:
<input type="text" name="user_tel" size="20">
</p>
<p><br>
留言:
<textarea name="user_post" rows="5" cols="20"></textarea>
</p>
<p>
<input type="submit" value="提交留言" name="Submit">
</p>
</form>
<br><br><br>
<font color="red">最新留言如下:<BR><BR></font>
<?php
if($_POST['Submit']){
$user_name=$_POST['user_name'];
$user_tel=$_POST['user_tel'];
$user_post=$_POST['user_post'];
$ah=$_POST['ah'];
$where=$_POST['where'];
$str.="姓名:".$user_name."\r\n電話:".$user_tel."\r\n留言:".$user_post;
$k=fopen("liuyanban.txt","w+");
fwrite($k,$str);
fclose($k);
echo "保存成功!";
}
?>
</body>
</html>
⑽ 誰能提供一個PHP留言板源碼
input.htm
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>input</title>
</head>
<body>
<form method="POST" action="receive.php">
<p>您的姓名: <input type="text" name="T1" size="20"></p>
<p>您的性別:男<input type="radio" value="0" name="R1">
女<input type="radio" name="R1" value="1"></p>
<p>您的EMAIL:<input type="text" name="T2" size="35"></p>
<p>您的留言內容:</p>
<p><textarea rows="16" name="S1" cols="45"></textarea></p>
<p> </p>
<p><input type="submit" value="提交" name="B1">
<input type="reset" value="重置" name="B2"></p>
</form>
</body>
</html>
receive.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$ip=getenv(REMOTE_ADDR);
$sql = "INSERT INTO `guestbook`.`gbook` (`id`, `name`, `sex`, `email`, `info`, `ip`, `time_at`) VALUES (NULL, '$T1', '$R1', '$T2', '$S1', '$ip', NOW());";
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
mysql_query($sql);
$result=mysql_query("select * from $table");
while ($arr=mysql_fetch_array($result))
{
if ($arr[2]==0)
$gender='先生';
else
$gender='女士';
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Receive</title>
</head>
<body style="background-attachment: fixed">
<table border="1" width="100%" id="table1" bgcolor="#FFFFFF">
<tr>
<td bordercolor="#FFFFFF" bgcolor="#C0C0C0"><?=$arr[6]?>(<?=$arr[5]?>)<p><?=$arr[1]?> <?=$gender?><<a href="<?=$arr[3]?>"><?=$arr[3]?></a>>
寫到:</td>
</tr>
<tr>
<td><?=$arr[4]?><p> </p>
<p><a href="del.php?id=<?=$arr[0]?>">[刪除]</a>
<a href="modify.php?id=<?=$arr[0]?>">[修改]</a>]</td>
</tr>
</table>
</body>
</html>
<?php
echo '<p>';
echo '<p>';
}
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建網頁 1</title>
</head>
<body>
<p><a href="input.htm"><繼續留言></a></p>
</body>
</html>
del.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$sql="DELETE FROM $table WHERE id=$id";
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
$result=mysql_query($sql);
if ($result)
echo "刪除成功";
else
echo "刪除失敗";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建網頁 1</title>
</head>
<body>
<p><a href="receive.php"><返回首頁></a></p>
</body>
</html>
modify.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$ip=getenv(REMOTE_ADDR);
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
$result=mysql_query("select * from $table where id=$id");
$arr=mysql_fetch_array($result);
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>input</title>
</head>
<body>
<form method="POST" action="modify_ok.php?id=<?=$id?>">
<p>您的姓名: <input type="text" name="T1" size="20" value="<?=$arr[1]?>"></p>
<p>您的性別:
<?php
if ($arr[2]==0) echo '男<input type="radio" value="0" name="R1" checked>
女<input type="radio" name="R1" value="1"></p>';
else echo '男<input type="radio" value="0" name="R1">
女<input type="radio" name="R1" value="1" checked></p>';
?>
<p>您的EMAIL:<input type="text" name="T2" size="35" value="<?=$arr[3]?>"></p>
<p>您的留言內容:</p>
<p><textarea rows="16" name="S1" cols="45" ><?=$arr[4]?></textarea></p>
<p> </p>
<p><input type="submit" value="修改" name="B1">
<input type="reset" value="重置" name="B2"></p>
</form>
</body>
</html>
modify_ok.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);;
$sql = "UPDATE `guestbook`.`gbook` SET `name` = '$T1', `sex` = '$R1', `email` = '$T2', `info` = '$S1' WHERE `gbook`.`id` = '$id' LIMIT 1;";
$result=mysql_query($sql);
if ($result)
echo "修改成功";
else
echo "修改失敗";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建網頁 1</title>
</head>
<body>
<p><a href="input.htm"><繼續留言></a></p>
</body>
</html>