带Oracle数据库分页显示功能的留言簿(2)
oracle|分页|数据|数据库|显示
再来就是整理资料,以便置入 Oracle 资料库中
$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')";
$serial 变数为独一无二的字串,程序先乱数产生独特的字串,再用 md5 编码,将字串弄乱,形成类似杂凑处理后的无意义字串。由于字串长,又变得很乱,可防止使用者,尤其是骇客或飞客利用序号来戳系统。
$ref 变数目前是无效的。$id 变数为使用者认证用,若在程序开始处有加入使用者认证的程序,则 $PHP_AUTH_USER 会变成使用者的帐号,传入 $id 变数中。
至于使用者写的字串,为了防止资料库或处理时的复杂性甘脆将它用 BASE64 编码。可以让中文字的奇怪字元一字消失,当然这是锯箭法,不过对 Web 程序而言,执行快速、修改方便才是最重要的,实在没有必要再浪费精力去处理这些中文的冲码问题了。值得注意的是使用 BASE64 编码,会让字串膨胀大约 1/3,若资料库的储存空间有限,可能就不适合用这个方法了,话又说回来,现在硬碟便宜,随便就是十几 GB 以
上,应该不会考虑资料库空间有限的问题才对。
最后,将变数整理成 $query 字串,供资料库执行 SQL 指令使用就可以了。
ora_parse($cursor, $query) or die;
ora_exec($cursor);
ora_close($cursor);
ora_logoff($handle);
要执行 Oracle 的 SQL 指令前,要先经过 parse 的动作。若在前面加上 @ (如: @ora_prase();),可以不让使用者看到错误讯息。在执行 query 指令后,就可以关闭与 Oracle 之间的连线了。
Header("Location: ./index.php");
exit;
这二行让浏览器重导到 index.php。让使用者看到他的新留言,就完成了留言的动作。
之后来看看留言的内容显示程序。
<html>
<head>
<meta content="text/html; charset=gb2312"
http-equiv=Content-Type>
<title>留言版</title>
</head>
<body bgcolor=ffffff>
<?php
file://---------------------------
// 留言显示程序 index.php
// Author: Wilson Peng
// Copyright (C) 2000
file://---------------------------
$WebmasterIPArray =
ay(
"10.0.1.30", // 管理人员甲的机器 IP
"10.0.2.28" // 管理人员乙的机器 IP
);
$WebmasterIP=false;
for ($i=0; $i<Count($WebmasterIPArray); $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 "<a href=addmsg.php>新增留言....</a><p>\n";
if ($QUERY_STRING!="")
$page = $QUERY_STRING;
} else
$page = 0;
}
$i=count($guestbook);
$msgnum=20; // 每页二十笔
$start = $page * $msgnum;
$end = $start + $msgnum;
if ($end > $i) $end=$i;
$totalpage=$i/$msgnum;
$pagestr="";
if ($page>0) $pagestr=$pagestr."<a
href=index.php?".($page-1).">$pagestr=$pagestr."[第 ";
for ($i=0; $i<$totalpage; $i++)
if ($i!=$page)
$pagestr = $pagestr."<a href=index.php?$i>".($i+1)."</a> ";
} else
$pagestr = $pagestr.($i+1)." ";
}
}
$pagestr=$pagestr." 页] ";
if ($page<($totalpage-1)) $pagestr=$pagestr."- <a
href=index.php?".($page+1).">下页></a> ";
$pagestr="<div align=center>$pagestr</div>";
echo "<p>".$pagestr."<hr><p>\n";
for ($i=$start; $i<$end; $i++)
echo "<p><hr><p>\n";
echo "<p>\n<font color=e06060>".$guestbook[$i][5]."</font>
";
if ($guestbook[$i][6]!="") echo "<a
href=mailto:".$guestbook[$i][6].">";
echo "<strong>".$guestbook[$i][3]."</strong>";
if ($guestbook[$i][6]!="") echo "</a>";
echo "<br>\n";
if ($WebmasterIP) echo "<a
href=erase.php?".$guestbook[$i][0].">删除本篇!!</a> (".$guestbook[$i][2].")
";
echo "<font size=-1 color=c0c0c0>from:
".$guestbook[$i][4]."</font><p>\n";
$msg=base64_decode($guestbook[$i][7]);
$msg=nl2br($msg);
echo $msg;
echo "<p>\n";
}
echo "<p><hr><p>\n";
echo $pagestr;
?>
</body>
</html>
在显示留言的部份,考虑到留言内容若很多,加上网路慢的话,可能会让使用者在线路慢的时候拖累整个资料库,因此,尽快的连上资料库,取得需要的资料后,马上关闭资料库,再慢慢送给使用者,应是最好的对策。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

Detailed explanation of the role and usage of the echo keyword in PHP PHP is a widely used server-side scripting language, which is widely used in web development. The echo keyword is a method used to output content in PHP. This article will introduce in detail the function and use of the echo keyword. Function: The main function of the echo keyword is to output content to the browser. In web development, we need to dynamically present data to the front-end page. At this time, we can use the echo keyword to output the data to the page. e

The most popular Go frameworks at present are: Gin: lightweight, high-performance web framework, simple and easy to use. Echo: A fast, highly customizable web framework that provides high-performance routing and middleware. GorillaMux: A fast and flexible multiplexer that provides advanced routing configuration options. Fiber: A performance-optimized, high-performance web framework that handles high concurrent requests. Martini: A modular web framework with object-oriented design that provides a rich feature set.

As a fast and efficient programming language, Go language has always been favored by programmers. In the Go language ecosystem, frameworks play a vital role in helping developers build applications faster. This article will introduce five Go language frameworks to let you understand their characteristics and usage. 1. Gin framework The Gin framework is a lightweight Web framework with fast and high performance characteristics. Use the Gin framework to quickly build RESTful APIs and web applications. Here is a simple example code:

With the development of the Internet and the advancement of information technology, the era of big data has arrived, and fields such as data analysis and machine learning have also been widely used. In these fields, task scheduling is an inevitable problem. How to achieve efficient task scheduling is crucial to improving efficiency. In this article, we will introduce how to use Golang's web framework Echo framework to implement distributed task scheduling. 1. Introduction to the Echo framework Echo is a high-performance, scalable, lightweight GoWeb framework. It is based on HTTP

As an efficient and modern programming language, Go language is widely favored by developers. In the Go language, there are many excellent frameworks that can help developers quickly build efficient and stable applications. This article will introduce some popular frameworks in the Go language and provide some specific code examples. Gin framework Gin is a very popular Goweb framework that provides the ability to quickly develop APIs. The Gin framework has the characteristics of high performance, ease of use, and lightweight, and is widely used in back-end development of Internet companies.
