Most websites in the PHP guestbook (with the display function of Oracle Database paging) will consider the interaction with users. In this case, the message board function allows users to stay on this tour or interact with the website. <B most websites consider the interaction with users. In this case, the message board function allows users to stay on this tour or interact with the website.
In terms of design, you can leave only users' short messages, or design a complex Web BBS system based on its nature. Of course, how to create a message board for your website depends on the nature of the website and the clever thinking of Web site developers.
The example described here is a simple list of the content of all messages. Users can view multiple messages at a time. The system uses the Oracle 7.x database system to store messages at the backend. In this example, the database name is WWW, the connected user account is user38, and the password is iam3849. To use this example directly, you must first execute the following SQL command to create a guestbook data table.
Create table guestbook (
Serial varchar2 (255) not null,
Ref varchar2 (255) null,
Id char (8) not null,
Alias varchar2 (32) not null,
Ip varchar2 (1024) null,
Msgdate date not null,
Email varchar2 (1024) null,
Msg varchar2 (2000) not null,
Flag char (1) default 1,
Primary key (serial)
);
The fields and detailed information of the preceding SQL statements are described in the table below.
Serial number column name data form data length column description limit Key
0 serial number serial varchar2 255 NN PK
1 refer to the serial number ref varchar2 255 for temporary reservation. Supply back
Comment-over function
2 Account id char 8 user account NN
3 anonymous alias varchar2 32 display name NN
4 URL ip address varchar2 1024 IP address
5 Time msgdate date NN
6. email varchar2 1024
7 message content msg varchar2 2000 NN
8 display flag char 1 0: not displayed
1: Display (set)
If the user authentication function is added to the message board related programs in this section, you can leave the user's authentication account in the account column of the guestbook data table, so that the Webmaster can find an improper sender in the future. Leave a column here for the readers to practice.
To use the program in this section, first install Oracle 7.x, and determine that SQL * net on the Web Server can be smoothly connected to the Oracle database. And then add
-- With-oracle =/home/oracle/product/7.3.2 option, of course, it does not matter if it is changed to another path, as long as the path is really the path of Oracle. For more information about Oracle installation and usage, see related books.
The following program adds the user's message information to the guestbook message table. If you want to set the user authentication function, you can check at the beginning of the program, the sender of the message can confirm the identity, and read the message does not have to check the identity. This setting prevents improper speech, but does not allow the message function to be used by only a few people.
File ://---------------------------
// Add the message program addmsg. php
// Author: Wilson Peng
// Copy right (C) 2000
File ://---------------------------
//
// You can add the identity check function here.
//
If ($ alias! = "") And ($ msg! = "")){
Putenv ("ORACLE_SID = WWW ");
Putenv ("NLS_LANG = american_taiwan.zht16big5 ");
Putenv ("ORACLE_HOME =/home/oracle/product/7.3.2 ");
Putenv ("LD_LIBRARY_PATH =/home/oracle/product/7.3.2/lib ");
Putenv ("ORA_NLS =/home/oracle/product/7.3.2/ocommon/nls/admin/data ");
Putenv ("ORA_NLS32 =/home/oracle/product/7.3.2/ocommon/nls/admin/data ");
$ Handle = ora_logon ("user38 @ WWW", "iam3849") or die;
$ Cursor = ora_open ($ handle );
Ora_commitoff ($ handle );
$ Serial = md5 (uniqid (rand ()));
$ Ref = "";
$ Id = $ PHP_AUTH_USER;
$ Ip = $ REMOTE_ADDR;
$ Msg = base64_encode ($ msg );
$ Flag = "1 ";
$ Query = "INSERT into guestbook (serial, ref, id, alias, ip,
Msgdate, email, msg, flag) values ('$ serial', '$ ref', '$ ID',' $ alias ',' $ IP ',
Sysdate, '$ email', '$ msg', '$ flag ')";
Ora_parse ($ cursor, $ query) or die;
Ora_exec ($ cursor );
Ora_close ($ cursor );
Ora_logoff ($ handle );
Header ("Location:./index. php ");
Exit;
} Else {
?>
Enter message
}
?>
When the above program is running, check whether the variables alias and msg have information. if there is no information, send the form to the user for the user to fill in the message.
If the user fills in the message and presses the "send message" button, the first half of the program is executed.
The program is divided into five parts.
1. set the environment variables required by Oracle
2. connect to the Oracle database
3. sort data and send it to Oracle
4. end the connection with Oracle
5. end the program and display the latest message
In the Oracle environment setting section, you can use PHP's putenv () function to set environment variables at the job system layer. To use Chinese, remember to join the following line
Putenv ("NLS_LANG = american_taiwan.zht16big5 ");
Then we will use the Oracle function library function: ora_logon () and so on. For details, see the Oracle database function library. Using this function library, you can easily operate the Oracle database.
The next step is to organize the data so that it can be placed into the Oracle database.
$ Serial = md5 (uniqid (rand ()));
$ Ref = "";
$ Id = $ PHP_AUTH_USER;
$ Ip = $ REMOTE_ADDR;
$ Msg = base64_encode ($ msg );
$ Flag = "1 ";
$ Query = "INSERT into guestbook (serial, ref, id, alias, ip, msgdate,
Email, msg, flag) values ('$ serial', '$ ref', '$ ID',' $ alias ',' $ IP', sysdate,
'$ Email', '$ msg', '$ flag ')";
The $ serial variable is a unique string. the program generates a unique string in disorder and uses md5 encoding to confuse the string to form a meaningless string similar to a collection. Because the string is long and messy, it can prevent the user, especially the hacker or flying passenger, from using the serial number to stamp the system.
$ Ref variable is currently invalid. The $ id variable is used for user authentication. if a user authentication program is added at the beginning of the program, $ PHP_AUTH_USER is changed to the user's account and is passed in to the $ id variable.
As for the string written by the user, it is Base64-encoded to prevent the complexity of the database or processing. This can make the strange characters in Chinese text disappear. of course, this is the saw arrow method. However, it is most important for Web programs to execute fast and easily modify, there is no need to waste time dealing with the issue of these Chinese text. It is worth noting that using BASE64 encoding will increase the string size by about 1/3. if the storage space of the database is limited, it may not be suitable for this method. In other words, hard disks are cheap now, just a dozen or more GB
The problem of limited database space should not be considered.
Finally, sort the variables into $ query strings for the database to execute SQL commands.
Ora_parse ($ cursor, $ query) or die;
Ora_exec ($ cursor );
Ora_close ($ cursor );
Ora_logoff ($ handle );
Before executing Oracle SQL commands, you must first perform the parse action. If @ (for example, @ ora_prase ();) is added to the front, the user cannot see the error message. After executing the query command, you can close the connection with Oracle.
Header ("Location:./index. php ");
Exit;
These two lines allow the browser to re-export to index. php. When the user sees his new message, the message is completed.
Then let's look at the message content display program.
Http-equiv = Content-Type>
Message Board
File ://---------------------------
// Index. php
// Author: Wilson Peng
// Copy right (C) 2000
File ://---------------------------
$ WebmasterIPArray =
Ay (
"10.0.1.30", // server IP address of administrator
"10.0.2.28" // IP address of administrator B
);
$ WebmasterIP = false;
For ($ I = 0; $ I If ($ REMOTE_ADDR ==$ WebmasterIPArray [$ I]) $ WebmasterIP = true;
}
Putenv ("ORACLE_SID = WWW ");
Putenv ("NLS_LANG = american_taiwan.zht16big5 ");
Putenv ("ORACLE_HOME =/home/oracle/product/7.3.2 ");
Putenv ("LD_LIBRARY_PATH =/home/oracle/product/7.3.2/lib ");
Putenv ("ORA_NLS =/home/oracle/product/7.3.2/ocommon/nls/admin/data ");
Putenv ("ORA_NLS32 =/home/oracle/product/7.3.2/ocommon/nls/admin/data ");
$ Handle = ora_logon ("user38 @ WWW", "iam3849") or die;
$ Cursor = ora_open ($ handle );
Ora_commitoff ($ handle );
$ Query = "SELECT serial, ref, id, alias, ip, TO_CHAR (msgdate, 'yyyy/mm/dd hh: mi: SS'), email, msg FROM guestbook where flag = '1' order by msgdate desc ";
Ora_parse ($ cursor, $ query) or die;
Ora_exec ($ cursor );
$ I = 0;
While (ora_fetch ($ cursor )){
$ Guestbook [$ I] [0] = ora_getcolumn ($ cursor, 0 );
$ Guestbook [$ I] [1] = ora_getcolumn ($ cursor, 1 );
$ Guestbook [$ I] [2] = ora_getcolumn ($ cursor, 2 );
$ Guestbook [$ I] [3] = ora_getcolumn ($ cursor, 3 );
$ Gu
Estbook [$ I] [4] = ora_getcolumn ($ cursor, 4 );
$ Guestbook [$ I] [5] = ora_getcolumn ($ cursor, 5 );
$ Guestbook [$ I] [6] = ora_getcolumn ($ cursor, 6 );
$ Guestbook [$ I] [7] = ora_getcolumn ($ cursor, 7 );
$ I ++;
}
Ora_close ($ cursor );
Ora_logoff ($ handle );
Echo "added a message ....
";
If ($ QUERY_STRING! = "")
$ Page = $ QUERY_STRING;
} Else
$ Page = 0;
}
$ I = count ($ guestbook );
$ Msgnum = 20; // 20 pens per page
$ Start = $ page * $ msgnum;
$ End = $ start + $ msgnum;
If ($ end> $ I) $ end = $ I;
$ Totalpage = $ I/$ msgnum;
$ Pagestr = "";
If ($ page> 0) $ pagestr = $ pagestr. "href = index. php? ". ($ Page-1)."> <上页 - ";
$ Pagestr = $ pagestr. "[No ";
For ($ I = 0; $ I <$ totalpage; $ I ++)
If ($ I! = $ Page)
$ Pagestr = $ pagestr. "". ($ I + 1 )."";
} Else
$ Pagestr = $ pagestr. ($ I + 1 )."";
}
}
$ Pagestr = $ pagestr. "Page]";
If ($ page <($ totalpage-1) $ pagestr = $ pagestr. "-href = index. php? ". ($ Page + 1)."> Next page> ";
$ Pagestr = "$ pagestr ";
Echo"
". $ Pagestr ."
";
For ($ I = $ start; $ I <$ end; $ I ++)
Echo"
";
Echo"
". $ Guestbook [$ I] [5]."
";
If ($ guestbook [$ I] [6]! = "") Echo "href = mailto:". $ guestbook [$ I] [6]. "> ";
Echo"". $ Guestbook [$ I] [3]."";
If ($ guestbook [$ I] [6]! = "") Echo "";
Echo"
";
If ($ WebmasterIP) echo "href = erase. php? ". $ Guestbook [$ I] [0]."> delete this article !! (". $ Guestbook [$ I] [2].")
";
Echo "from:
". $ Guestbook [$ I] [4]."
";
$ Msg = base64_decode ($ guestbook [$ I] [7]);
$ Msg = nl2br ($ msg );
Echo $ msg;
Echo"
";
}
Echo"
";
Echo $ pagestr;
?>
When a message is displayed, the user may be dragged down to the entire database when the line is slow, considering that there are many messages and the network is slow. Therefore, you can connect to the database as soon as possible, it is the best countermeasure to immediately close the database and send it to users after obtaining the required information.
The program is divided into four parts
1. initialization
2. retrieve data from the database
3. calculate the number of pages to be displayed
4. send documents
This program is implemented on BIGLOBE. as this is an ISP company, you can set a time limit for this application.
Only connected or leased line members can see it. before entering, enter the account and password. If you are interested, you may wish to buy a BIGLOBE
Dial account reference. To protect the privacy of the message Holder, the message is mosaic.
$ WebmasterIPArray = array (
"10.0.1.30", // server IP address of administrator
"10.0.2.28" // IP address of administrator B
);
$ WebmasterIP = false;
For ($ I = 0; $ I If ($ REMOTE_ADDR ==$ WebmasterIPArray [$ I]) $ WebmasterIP = true;
}
// Initialize the Oracle program
The display program is similar to the initialization part of the message program, but the display program adds a function to set the Webmaster computer. Add the IP Address used by the Webmaster to the $ WebmasterIPArray array variable. when a message is displayed, the deleted message string is displayed, facilitating improper message handling.
$ Handle = ora_logon ("user38 @ WWW", "iam3849") or die;
$ Cursor = ora_open ($ handle );
Ora_commitoff ($ handle );
$ Query = "SELECT serial, ref, id, alias, ip, TO_CHAR (msgdate,
'Yyyy/mm/dd hh: mi: SS'), email, msg FROM guestbook where flag = '1' order
Msgdate desc ";
Ora_parse ($ cursor, $ query) or die;
Ora_exec ($ cursor );
$ I = 0;
While (ora_fetch ($ cursor )){
$ Guestbook [$ I] [0] = ora_getcolumn ($ cursor, 0 );
$ Guestbook [$ I] [1] = ora_getcolumn ($ cursor, 1 );
$ Guestbook [$ I] [2] = ora_getcolumn ($ cursor, 2 );
$ Guestbook [$ I] [3] = ora_getcolumn ($ cursor, 3 );
$ Guestbook [$ I] [4] = ora_getcolumn ($ cursor, 4 );
$ Guestbook [$ I] [5] = ora_getcolumn ($ cursor, 5 );
$ Guestbook [$ I] [6] = ora_getcolumn ($ cursor, 6 );
$ Guestbook [$ I] [7] = ora_getcolumn ($ cursor, 7 );
$ I ++;
}
Ora_close ($ cursor );
Ora_logoff ($ handle );
After initialization, you can connect to the Oracle database and put the messages in the $ guestbook array. After obtaining the information, close the database and process the $ guestbook array.
If ($ QUERY_STRING! = ""){
$ Page = $ QUERY_STRING;
} Else {
$ Page = 0;
}
The program determines the page number, and the internal value is the first page. To display the page on the third page, use http: // xxxxxx/index. php? The format of 2, that is, $ QUERY_STRING, and so on. The subsequent data path is used to process the displayed pages and records.
$ Msgnum = 20; // 20 pens per page
To change the number of display records on each page, you can change the $ msgnum variable. The program's internal value is 20.
For ($ I = $ start; $ I <$ end; $ I ++ ){
Echo"
";
Echo"
". $ Guestbook [$ I] [5]." ";
If ($ guestbook [$ I] [6]! = "") Echo "href = mailto:". $ guestbook [$ I] [6]. "> ";
Echo"". $ Guestbook [$ I] [3]."";
If ($ guestbook [$ I] [6]! = "") Echo "";
Echo"
";
If ($ WebmasterIP) echo "delete
This article !! (". $ Guestbook [$ I] [2].") ";
Echo "from:
". $ Guestbook [$ I] [4]."
";
$ Msg = base64_decode ($ guestbook [$ I] [7]);
$ Msg = nl2br ($ msg );
Echo $ msg;
Echo"
";
}
This section of the program is the program that truly shows the message information to the user. Use the for loop to retrieve the data of the $ guestbook array according to the specified page number and display it to the user. It is worth mentioning that if the IP address of the machine reading the message is an element in the $ WebmasterIPArray variable array, it will display "delete this article !! For the management personnel to delete improper messages.
The following is the program for deleting messages.
File ://---------------------------
// Leave a message to delete the program erase. php
// Author: Wilson Peng
// Copy right (C) 2000
File ://---------------------------
Putenv ("ORACLE_SID = WWW ");
Putenv ("NLS_LANG = american_taiwan.zht16big5 ");
Putenv ("ORACLE_HOME =/home/oracle/product/7.3.2 ");
Putenv ("LD_LIBRARY_PATH =/home/oracle/product/7.3.2/lib ");
Putenv ("ORA_NLS =/home/oracle/product/7.3.2/ocommon/nls/admin/data ");
Putenv ("ORA_NLS32 =/home/oracle/product/7.3.2/ocommon/nls/admin/data ");
$ Handle = ora_logon ("user38 @ WWW", "iam3849") or die;
$ Cursor = ora_open ($ handle );
Ora_commitoff ($ handle );
$ Query = "UPDATE guestbook set flag = '0' where
Serial = '". $ QUERY_STRING ."'";
Ora_parse ($ cursor, $ query) or die;
Ora_exec ($ cursor );
Ora_close ($ cursor );
Ora_logoff ($ handle );
Header ("Location:./index. php ");
?>
In fact, this program is simple. you only need to open the Oracle database and set the flag field of the document whose serial number you want to delete to 0. you do not need to remove the information from the database.