Recently, I have been using php + dbfile to develop blogs. I learned a lot during the development process, so I tried to write a small message book.
This message book using php + dbfile, do not need to use the database, can be used in the blog, such as http://www.customyze.com, this blog in the Tag Board is the message book.
The entire message book requires four files: board. php, index. php, config. php, and admin. php.
Board. php is used to store data. You can add a message record in it first. Code copy box
<? Php $ Board = array (1081410332, 'test', 'test message exist', 'HTTP: // www.piscdong.com ');?>
[Ctrl + A select all and copy]
Index. php is the page for message display and submission. Code copy box
<? Phprequire_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: // '.html specialchars (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> message book </title> <meta http-equiv =" Content-Type "content =" text/html; charset = gb2312 "/> [Ctrl + A select all and copy]
Config. php stores the password for managing the message book, and stores the password in a separate file for ease of modification. Code copy box
<? Php $ password = '000000';?>
[Ctrl + A select all and copy]
Admin. php is used to manage pages. It has simple functions and can only delete messages. You need to enter the management password When deleting the password and store it in config. php. Code copy box
<? Phprequire_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> Manage message books </title> <meta http-equiv =" Content-Type "content =" text/html; charset = gb2312 "/> [Ctrl + A select all and copy]
This message book is still very simple and its functions are not perfect. For example, it can be improved without paging. :-)