Guest Book with Oracle database paging display (2)

Source: Internet
Author: User
Tags base64 count sql variables query string variable oracle database
oracle| Page | data | database | Display again is to organize the data to be placed in Oracle database

$serial =md5 (rand ()) (uniqid);
$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 ');

$serial variable is a unique string, the program first chaos number to produce a unique string, and then use MD5 encoding, the string chaos, form a hash-like processing after the meaningless string. Because the string length, and become very messy, can prevent users, especially hackers or visitors using serial number to stamp the system.

The $REF variable is currently invalid. $id variables for the user authentication, if the program at the beginning of the user certification to join the program, then $PHP _auth_user will become the user's account, passed into $id variables.

As for the user-written string, to prevent the complexity of the database or processing, it is BASE64 encoded. Can let the text of the strange characters disappear, of course, this is the saw arrows, but for the WEB program, the implementation of fast, easy to modify is the most important, there is no need to waste energy to deal with these Chinese punching code problem. It is worth noting that the use of BASE64 encoding, will allow the string expansion of about 1/3, if the database storage space is limited, may not be suitable for this method, and then said back, now the hard disk is cheap, casually is more than 10 GB to
, you should not consider the problem of limited database space.

Finally, the variables are sorted into $query strings for use by the database to execute the SQL instructions.

Ora_parse ($cursor, $query) or die;
Ora_exec ($cursor);
Ora_close ($cursor);
Ora_logoff ($handle);

Before you can execute an Oracle SQL directive, go through the parse action. If you precede with an @ (for example, @ora_prase ();), you can keep the user from seeing the error message. After you execute the query command, you can close the connection to Oracle.

Header ("Location:./index.php");
Exit

These two lines allow the browser to redirect to index.php. Let the user see his new message, the completion of the message action.

Then take a look at the message content display program.



http-equiv=content-type>
Message Board


file://---------------------------
Message Display program index.php
Author:wilson Peng
Copyright (C) 2000
file://---------------------------

$WebmasterIPArray =
Ay
"10.0.1.30",//management personnel a machine IP
"10.0.2.28"//management personnel B's machine IP
);

$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 " new Message ....

\ n ";

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). " >< on page -";
$pagestr = $pagestr. " [subsection];
for ($i =0; $i $totalpage; $i + +)

if ($i!= $page)

$pagestr = $pagestr. " ";
} 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. "

\ n ";

for ($i = $start; $i $end; $i + +)

echo "

\ n";
echo "

\n". $guestbook [$i][5]. "
";
if ($guestbook [$i][6]!= "") echo Href=mailto: ". $guestbook [$i][6]." > ";
echo " ". $guestbook [$i][3]. " ";
if ($guestbook [$i][6]!= "") echo "";
echo "
\ n";
if ($WebmasterIP) echo " Href=erase.php? ". $guestbook [$i][0]. " > > delete this article!! (". $guestbook [$i][2].")
";
echo " from:
". $guestbook [$i][4]."

\ n ";
$msg =base64_decode ($guestbook [$i][7]);
$msg =nl2br ($msg);
Echo $msg;
echo "

\ n";
}

echo "

\ n";
Echo $pagestr;

? >

In the part that shows the message, considering the content of the message if a lot, plus the network slow, it may allow users to slow down the entire database when the line, therefore, as soon as possible to connect the database, to obtain the necessary information, immediately close the database, and then slowly to the user, should be the best countermeasures.




Related Article

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.