Example of a php text message book (1)

Source: Internet
Author: User

We all know the importance of databases for the network. due to the complexity of cgi, asp and php + mysql have become the mainstream. almost all personal webpages use message books, but the requested message books are unstable. this has caused a lot of inconvenience for online communication. therefore, more and more friends wish to have their own message books.
However, few free personal homepages support asp and php. I recommend you now Osso Network (http://www.oso.com.cn) Support php. this gives you the foundation to have your own message book. now, I will use an example in a text message book to describe the simple use of php.
First, let's determine the process of leaving a message: Write, send, and view the message. (Search) and so on. for Bamboo, it is indispensable to manage message books. in this way, we may wish to locate 6 PHP files and 1 text file. the six PHP files are: guest. php manage. php reply. php sys. php del. php edit. php, 1 text file: guest.txt
Let's take a look at the content of guest. php. Of course, you can directly put the following content on your php webpage. Please respect the work of the author. Thank you.
----------------------
// Guest. php: <?

Require ("sys. php ");
If ($ B1)
{
If ($ message = "" or $ name = "")
{
$ Errorm = "<font color = red> Error !!! </Font> the name and message content are required ";
}
Else
{
# Writing data
$ Space = "";
$ Time = date (Y, m, D, H, I );
$ Ip = $ REMOTE_ADDR;
$ Name = encode ($ name );
$ Homepage = encode ($ homepage );
$ From = encode ($ from );
$ Email = encode ($ email );
$ Message = StripSlashes ($ message );
$ Message = htmlspecialchars ($ message );
$ Message = check_strlen_long ($ message );
$ Message = nl2br ($ message );
$ Guestcontent = "<tr> <td> <font color = # AB00E1> message content: </font> <br> <! -- Content> $ message <! -- Endcontent> ";
$ Guestcontent = $ guestcontent. "<br> <font color = # 6633FF> The name of the speaker is: </font> <! -- Name> $ name <! -- Endname> ";
If ($ email! = "")
{$ Guestcontent = $ guestcontent. "<br> <font color = # 9900CC> email box </font> <a href = \" mailto: $ email \ "> <! -- Email> $ email <! -- Endemail> </a> "." $ space ";}
If ($ homepage! = "Http ://")
{$ Guestcontent = $ guestcontent. "<font color = # 9900CC> Home Page: </font> $ hompage <a href = \" $ homepage \ "> <! -- Homepage> $ homepage <! -- Endhomepage> </a> ";}
$ Guestcontent = $ guestcontent. "<br> <font color = # 0000FF> time: $ time from: <! -- From> $ from <! -- Endfrom> $ ip </font> ";
$ Guestcontent = ereg_replace (chr (10), "", $ guestcontent );
$ Guestcontent = $ guestcontent. "$ Fp = fopen ($ guestfile, "");
Fputs ($ fp, $ guestcontent );
Fclose ($ fp );
}
}


?>

<Html>
<Head>
<Title> zihanonlinegbook </title>
<Style>
<! --
A: link {text-decoration: none; color: 0000ff}
A: visited {text-decoration: none; color: 004080}
A: active {text-decoration: none}
A: hover {text-decoration: underline; color: ff0000}
BODY {FONT-SIZE: 10pt}
TH {FONT-SIZE: 10 pt}
TD {FONT-SIZE: 10pt}
TEXTAREA
{
FONT-FAMILY: "";
FONT-SIZE: 10pt;
}

-->
</Style>
<Body bgcolor = # FFFFFD background = "bg.jpg">
<Div align = "center">
<? Include('head.htm');?>
<Table width = "68%" border = "1" cellpadding = "3" cellspacing = "0" bordercolor = "# E3E3E3">
<Form method = "POST" action = "guest. php">
<?
If ($ errorm)
{
Echo "<tr> ";
Echo "<td colspan = 3 height = 32> ";
Echo "$ errorm ";
Echo "</td> ";
Echo "</tr> ";
}
?>
<Tr>
<Td width = "22%" bgcolor = "# F0F0F0"> <font color = "#000000"> name <font color = "# FF0033"> (required) </font> </td>
<Td colspan = "2" width = "78%" bgcolor = "# F0F0F0"> <font color = "#00FF00">
<Input type = "text" name = "name" size = "40">
</Font> </td>
</Tr>
<Tr>
<Td width = "22%" height = "29"> homepage: </td>
<Td colspan = "2" height = "29" width = "78%">
<Input type = "text" name = "homepage" size = "40" value = "http: //">
</Td>
</Tr>
<Tr>
<Td width = "22%" height = "27" bgcolor = "# F0F0F0"> from: </td>
<Td colspan = "2" height = "27" width = "78%" bgcolor = "# F0F0F0">
<Input type = "text" name = "from" size = "40">
</Td>
</Tr>
<Tr>
<Td width = "22%" height = "20"> Email: </td>
<Td colspan = "2" height = "20" width = "78%"> <font color = "#00FF00">
<Input type = "text" name = "email" size = "40">
</Font> </td>
</Tr>
<Tr>
<Td colspan = "3" valign = "middle" align = "left">
<Div align = "center"> <font color = "#000000"> Leave a message </font> <font color = "# FF0033"> (required) </font> <font color = "#00FF00"> <br>
<Textarea rows = "6" name = "message" cols = "55" wrap = "VIRTUAL"> </textarea>
</Font> </div>
</Td>
</Tr>
<Tr bgcolor = "# F0F0F0">
<Td colspan = "3" height = "24">
<Div align = "center"> <font color = "#00FF00">
<Input type = "submit" value = "sending" name = "B1">

<Input type = "reset" value = "re-write" name = "B2">
</Font> </div>
</Td>
</Tr>
</Form>
</Table>
<Table width = "68%" border = "1" cellpadding = "4" cellspacing = "0" bordercolor = "# E3E3E3">
<Tr>
<Td>
<Table width = "100%" border = "0" cellpadding = "0" cellspacing = "0">
<Form action = manage. php method = post>
<Tr>
<Td colspan = "2">
<Input type = hidden name = dispflag value = show>
Password Management:
<Input type = password name = password size = 8>

<Input type = submit value = "Confirm" name = "submit">
</Td>
</Tr>
</Form>
</Table>
</Td>
<Td>
<Table width = "100%" border = "0" cellpadding = "0" cellspacing = "0">
<Form action = guest. php method = post>
<Tr>
<Td> enter keywords:
<Input type = "text" name = "keyword" size = "10">
<Input type = "submit" name = "search" value = "search message">
</Td>
</Tr>
</Form>
</Table>
</Td>
</Tr>
</Table>
<?
Function search ($ keyword)
{
Global $ content;
$ Count = count ($ content );
$ Subscript = 0;
$ ArrSearch = array ();
For ($ I = 0; $ I <$ count; $ I ++)
{
If (ereg ($ keyword, $ content [$ I])
{
$ ArrSearch [$ subscript] = ereg_replace ($ keyword, "<font color = red> $ keyword </font>", $ content [$ I]);
$ Subscript ++;
}
}
Return $ ArrSearch;
} // End function
$ One_page_line = 15;
$ Content = file ($ guestfile );
If (isset ($ search) and isset ($ keyword) and $ keyword! = "")
{
$ Content = search ($ keyword );
}
$ Count = count ($ content );
?>
<Table width = "68%" border = "0">
<Tr>
<Td>

<?
$ Int_page_count = $ count; // The total number of entries;
$ Int_page_num = ceil ($ int_page_count/$ one_page_line); // total number of pages;
Echo "<font color = # CC33FF> page :";
For ($ I = 1; $ I <= $ int_page_num; $ I ++)
{
Echo "<a href = guest. php? Page = $ I> ". $ I." </a> ";
}
Echo "</font> ";
If (isset ($ search) and isset ($ keyword) and $ keyword! = "")
{
Echo "<br> <center> ";
Echo "the following message contains keywords <font color = red> $ keyword </font> <font color = red> ". $ count. "</font> entries </center> ";
}
?>
</Td> <p align = right> total <font color = red> <? Echo "$ count"?> </Font> entries </p> </td>
</Tr>
</Table>
</Div>
<Br>
<Table width = "68%" border = "0" align = "center">
<?
If ($ page = "" or! Isset ($ page ))
{$ Page = 1 ;}
$ Text = "";
$ Begin_line = $ int_page_count-($ page-1) * $ one_page_line;
If ($ begin_line <$ one_page_line) {$ one_page_line = $ begin_line ;}
For ($ j = $ begin_line; $ j> ($ begin_line-$ one_page_line); $ j --)
{
$ Text = $ text. "<tr> <td align = right colspan = 2> <a href = reply. php? Job = reply & record = ". $ j."> reply </a> <a href = edit. php? Record = ". $ j."> edit </a> <a href = dele. php? Record = ". $ j."> Delete </a> entry <font color = red> $ j </font> </td> </tr> ";
$ Text. = $ content [$ J-1];

// The subscript of the array starts from 0.
}

Echo "$ text ";
?>
</Table>
<?
Include('bottom.htm ');
?>
</Body>
</Html>
------------------
To be continued...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.