Home  >  Article  >  Backend Development  >  Develop small guestbook with php+dbfile_PHP tutorial

Develop small guestbook with php+dbfile_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:10:312801browse


最近一直在用php+dbfile开发blog,开发过程中学到了不少东西,于是就试着写了一个小留言本。
这个留言本采用php+dbfile,不需要使用数据库,可以放在blog中使用,比如http://www.customyze.com,这个blog中的Tag Board就是这个留言本。

整个留言本需要四个文件,分别是:board.php、index.php、config.php、admin.php。

board.php用来存储数据,可以先在里面添加了一条留言纪录。 代码拷贝框

[Ctrl+A 全部选择 然后拷贝]

index.php是留言显示和提交页面。 代码拷贝框
",$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"; $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{ ?> 留言本

'.($bd[3]!=''?'':'').$bd[1].($bd[3]!=''?'':'').': '.$bd[2].'
-'.date("G:i, M j, Y",$bd[0]).''; prev($Board); } echo join($s,'

'); ?>
Name: URL/Email:


[Ctrl+A select all and then copy]

Config.php stores the password for managing the guestbook. Put the password in a separate file for easy modification. Code copy box

[Ctrl+A select all and copy]

admin.php is the management page, the function is very simple, only Messages can be deleted. When deleting, you need to enter the management password, which is stored in config.php. Code copy box
1){ unset($Board[intval($HTTP_POST_VARS['id'])]); for($i=0;$i"; $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{ ?> Manage Guestbook '.(count($Board)>1?'':'').''; next($Board); } echo join($s,''); ?>
'.($bd [3]!=''?'':'').$bd[1].($bd[3] !=''?'':'').': '.$bd[2].'
-'.date("G :i, M j, Y",$bd[0]).'
< /form>

[Ctrl+A to select all and then copy]

This guestbook is still very simple, and its functions are not yet complete, such as no paging, etc., and it can continue to be improved. :-)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314223.htmlTechArticleI have been using php+dbfile to develop my blog recently. I learned a lot during the development process, so I tried to write it. A small guestbook. This guestbook uses php+dbfile and does not require the use of a database...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn