欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php+dbfile開發(fā)小型留言本

 更新時(shí)間:2006年10月09日 00:00:00   作者:  

最近一直在用php+dbfile開發(fā)blog,開發(fā)過程中學(xué)到了不少東西,于是就試著寫了一個(gè)小留言本。
這個(gè)留言本采用php+dbfile,不需要使用數(shù)據(jù)庫(kù),可以放在blog中使用,比如http://www.customyze.com,這個(gè)blog中的Tag Board就是這個(gè)留言本。

整個(gè)留言本需要四個(gè)文件,分別是:board.php、index.php、config.php、admin.php。

board.php用來存儲(chǔ)數(shù)據(jù),可以先在里面添加了一條留言紀(jì)錄。 代碼拷貝框
<?php $Board=array( array(1081410332,'測(cè)試','測(cè)試留言本','http://www.piscdong.com') ); ?>
[Ctrl+A 全部選擇 然后拷貝]

index.php是留言顯示和提交頁(yè)面。 代碼拷貝框
<?php require_once('board.php'); function htmlencode($content){ $content=htmlspecialchars($content); $content=preg_replace("/\r/i","<br />",$content); return $content; } if($HTTP_SERVER_VARS['REQUEST_METHOD']=='POST'){ $configpath_parts1 = pathinfo($SCRIPT_FILENAME); $time=time(); $name=$HTTP_POST_VARS['name']; $url=(preg_match("/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/i",$HTTP_POST_VARS['url'])
$HTTP_POST_VARS['url']=='')?$HTTP_POST_VARS['url']:'http://'.htmlspecialchars(preg_replace("/https?\:\/\//i",'',$HTTP_POST_VARS['url']),ENT_QUOTES); $info=htmlencode($HTTP_POST_VARS['info']); if($name!='' && $info!=''){ $Board[]=array($time,$name,$info,$url); } for($i=0;$i<count($Board);$i++){ $bd=current($Board); $s[]="\tarray(".$bd[0].",'".$bd[1]."','".$bd[2]."','".$bd[3]."')"; next($Board); } $content="<?php\n\$Board=array(\n".join($s,",\n")."\n);\n?>"; $filename=$configpath_parts1['dirname'].'/'.'board.php'; if(is_writable($filename)
!file_exists($filename)){ if(!$handle=fopen($filename,'w')){ return false; } if(!fwrite($handle,$content)){ return false; } fclose($handle); }else{ return false; } header('Location:.'); }else{ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>留言本</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> </head> <body> <form method="post" name="form1" action=""> <table border="0" cellspacing="5" cellpadding="0" align="center"> <tr> <td> <div style="overflow:auto;height:250px;border:1px dotted #999999;padding:5px;word-wrap:break-word;width:400px;"> <?php end($Board); for($i=0;$i<count($Board);$i++){ $bd=current($Board); $s[]='<strong>'.($bd[3]!=''?'<a href="':'').(preg_match("/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/i",$bd[3])?'mailto:':'').$bd[3].(($bd[3]!='' && !preg_match("/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/i",$bd[3]))?'" target="_blank':'').($bd[3]!=''?'">':'').$bd[1].($bd[3]!=''?'</a>':'').':</strong> '.$bd[2].'<br/><em>-'.date("G:i, M j, Y",$bd[0]).'</em>'; prev($Board); } echo join($s,'<br/><br/>'); ?> </div> </td> </tr> <tr> <td align="center"> 名稱:<input type="text" name="name"/> URL/Email:<input type="text" name="url"/><br/> <textarea name="info" cols="40" rows="8"></textarea><br/> <input type="submit" value="發(fā)布"/> </td> </tr> </table> </form> </body> </html> <?php } ?>
[Ctrl+A 全部選擇 然后拷貝]

config.php中存放的是管理留言本的密碼,把密碼放在單獨(dú)一個(gè)文件中方便修改。 代碼拷貝框
<?php $password='123456'; ?>
[Ctrl+A 全部選擇 然后拷貝]

admin.php是管理頁(yè)面,功能很簡(jiǎn)單,只能刪除留言。在刪除時(shí)需要輸入管理密碼,管理密碼存放在config.php中。 代碼拷貝框
<?php require_once('board.php'); require_once('config.php'); if(isset($HTTP_POST_VARS['id']) && $HTTP_POST_VARS['id']!='' && addslashes($HTTP_POST_VARS['password'])==$password){ if(count($Board)>1){ unset($Board[intval($HTTP_POST_VARS['id'])]); for($i=0;$i<count($Board);$i++){ $bd=current($Board); $s[]="\tarray(".$bd[0].",'".$bd[1]."','".$bd[2]."','".$bd[3]."')"; next($Board); } $content="<?php\n\$Board=array(\n".join($s,",\n")."\n);\n?>"; $configpath_parts1 = pathinfo($SCRIPT_FILENAME); $filename=$configpath_parts1['dirname'].'/'.'board.php'; if(is_writable($filename)
!file_exists($filename)){ if(!$handle=fopen($filename,'w')){ return false; } if(!fwrite($handle,$content)){ return false; } fclose($handle); }else{ return false; } } header('Location:admin.php'); }else{ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>管理留言本</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> </head> <body> <table width="500" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#999999"> <?php for($i=0;$i<count($Board);$i++){ $bd=current($Board); $s[]='<tr><td bgcolor="#'.($i%2!=0?'ececec':'ffffff').'"><strong>'.($bd[3]!=''?'<a href="':'').(preg_match("/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/i",$bd[3])?'mailto:':'').$bd[3].(($bd[3]!='' && !preg_match("/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/i",$bd[3]))?'" target="_blank':'').($bd[3]!=''?'">':'').$bd[1].($bd[3]!=''?'</a>':'').':</strong> '.$bd[2].'<br/><em>-'.date("G:i, M j, Y",$bd[0]).'</em></td>'.(count($Board)>1?'<td bgcolor="#'.($i%2!=0?'ececec':'ffffff').'" align="center"><form method="post" action=""><input type="submit" value="刪除" /><input type="hidden" name="id" value="'.$i.'" /><input type="password" name="password" /></form></td>':'').'</tr>'; next($Board); } echo join($s,''); ?> </table> </body> </html> <?php } ?>
[Ctrl+A 全部選擇 然后拷貝]

這個(gè)留言本還很簡(jiǎn)單,功能上還不健全,比如沒有分頁(yè)等,還可以繼續(xù)完善。:-)

相關(guān)文章

最新評(píng)論