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.
CodeCopy box
<? PHP
$ Board = array (
Array (1081410332, 'test', 'test message topic ', 'HTTP: // www.piscdong.com ')
);
?>
[Ctrl + A select all and copy]
Index. php is the page for message display and submission.
Code copy box
<? 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: // '.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"/>
</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/> ');
?>
</Div>
</TD>
</Tr>
<Tr>
<TD align = "center">
Name: <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 = "publish"/>
</TD>
</Tr>
</Table>
</Form>
</Body>
</Html>
<? PHP }?>
[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
<? 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> Manage message books </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? 'Ecececec': '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? 'Ecececec': 'ffffff '). '"align =" center "> <form method =" Post "Action =" "> <input type =" Submit "value =" delete "/> <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 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. :-)