当前位置: 编程技术>php
本页文章导读:
▪模仿OSO的论坛(三)
post.php(发新贴子) <HTML><HEAD><TITLE>疑难问题</TITLE> <LINK href="/blog_article/mypic/style.css" rel=STYLESHEET type=text/css></HEAD> <?php if (!$cookie_user) {echo "<script language='javascript'>"; echo "p.........
▪在PHP3中实现SESSION的功能(一)
SESSION函数库:session.inc.php3 <?php if (!isset($__session_inc__)){ $__session_inc__=1; //require("cookie.inc.php3"); # ------------------------------------------------------------------- # Session Management v1.0 21.6.1998 # (c) Wild .........
▪我用php+mysql写的留言本
guestbook.php: <head> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title></title> <STYLE>A:link { COLOR: #002878; TEXT-.........
[1]模仿OSO的论坛(三)
来源: 互联网 发布时间: 2013-11-30
post.php(发新贴子)
<HTML><HEAD><TITLE>疑难问题</TITLE>
<LINK href="/blog_article/mypic/style.css" rel=STYLESHEET type=text/css></HEAD>
<?php
if (!$cookie_user)
{echo "<script language='javascript'>";
echo "parent.location.href='/blog_article/index.html'";
echo "</script>";}
else {include ("connect.inc.php");
$query = "select * from my_user where user='".$cookie_user."' and password='".$cookie_password."'";
$res = mysql_query($query);
if (!$res)
{echo "<script language='javascript'>";
echo "parent.location.href='/blog_article/index.html'";
echo "</script>";}
include "connect.inc.php";
if ($theme) {$content=htmlspecialchars($content);
$content=nl2br($content);
$theme=htmlspecialchars($theme);
$theme=nl2br($theme);
$query = "INSERT INTO guestbook (name,type,theme,content,icon,time_open,time_close,answer_count,answer_name) VALUES ('".$cookie_user."',1,'".$theme."','".$content."',".$icon.",now(),now(),1,'".$cookie_user."')";
$res = mysql_query($query);
if ($res)
{echo "<script language='javascript'>";
echo "parent.location.href='/blog_article/post_end.html'";
echo "</script>";}
else echo $query;}}
?>
<SCRIPT language=JavaScript>
<!--
var submitcount=0;
function check_com(){
if(document.form.theme.value.length ==0){
submitcount--;
alert("主题不能为空!nYou must supply a subject.");
return false;
}
if(document.form.content.value.length == 0){
submitcount--;
alert("加贴内容不能为空!nYou must supply a message.");
return false;
}
return true;
}
//-->
</SCRIPT>
<BODY bgColor=#cccc99 bottomMargin=0 leftMargin=0 topMargin=0 marginwidth="0" marginheight="0">
<TABLE border=0 cellPadding=0 cellSpacing=0 width="100%" mypic/x.js"></SCRIPT>
<TR>
<TD vAlign=top>
<FORM action=post.php?forum_id=11 method=post name=form
onsubmit="return check_com()">
<TABLE align=center border=0 cellPadding=4 cellSpacing=0 width=100%>
<TBODY>
<TR>
<TD mypic/icon1.gif"
width=18><INPUT name=icon type=radio value=2> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon2.gif"
width=18><INPUT name=icon type=radio value=3> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon3.gif"
width=18><INPUT name=icon type=radio value=4> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon4.gif"
width=18><INPUT name=icon type=radio value=5> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon5.gif"
width=18><INPUT name=icon type=radio value=6> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon6.gif"
width=18><INPUT name=icon type=radio value=7> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon7.gif"
width=18><BR><INPUT name=icon type=radio value=8> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon8.gif"
width=18><INPUT name=icon type=radio value=9> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon9.gif"
width=18><INPUT name=icon type=radio value=10> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon10.gif"
width=18><INPUT name=icon type=radio value=11> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon11.gif"
width=18><INPUT name=icon type=radio value=12> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon12.gif"
width=18><INPUT name=icon type=radio value=13> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon13.gif"
width=18><INPUT name=icon type=radio value=14> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon14.gif"
width=18></TD></TR>
<TR>
<TD return checkSubmit()" type=submit value=" 发 表 ">
<INPUT name=reset type=reset value=" 清 除 "> </TD></TR>
</TBODY></TABLE></FORM></TD></TR>
</TBODY></TABLE>
</FORM>
</html>
【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】
<HTML><HEAD><TITLE>疑难问题</TITLE>
<LINK href="/blog_article/mypic/style.css" rel=STYLESHEET type=text/css></HEAD>
<?php
if (!$cookie_user)
{echo "<script language='javascript'>";
echo "parent.location.href='/blog_article/index.html'";
echo "</script>";}
else {include ("connect.inc.php");
$query = "select * from my_user where user='".$cookie_user."' and password='".$cookie_password."'";
$res = mysql_query($query);
if (!$res)
{echo "<script language='javascript'>";
echo "parent.location.href='/blog_article/index.html'";
echo "</script>";}
include "connect.inc.php";
if ($theme) {$content=htmlspecialchars($content);
$content=nl2br($content);
$theme=htmlspecialchars($theme);
$theme=nl2br($theme);
$query = "INSERT INTO guestbook (name,type,theme,content,icon,time_open,time_close,answer_count,answer_name) VALUES ('".$cookie_user."',1,'".$theme."','".$content."',".$icon.",now(),now(),1,'".$cookie_user."')";
$res = mysql_query($query);
if ($res)
{echo "<script language='javascript'>";
echo "parent.location.href='/blog_article/post_end.html'";
echo "</script>";}
else echo $query;}}
?>
<SCRIPT language=JavaScript>
<!--
var submitcount=0;
function check_com(){
if(document.form.theme.value.length ==0){
submitcount--;
alert("主题不能为空!nYou must supply a subject.");
return false;
}
if(document.form.content.value.length == 0){
submitcount--;
alert("加贴内容不能为空!nYou must supply a message.");
return false;
}
return true;
}
//-->
</SCRIPT>
<BODY bgColor=#cccc99 bottomMargin=0 leftMargin=0 topMargin=0 marginwidth="0" marginheight="0">
<TABLE border=0 cellPadding=0 cellSpacing=0 width="100%" mypic/x.js"></SCRIPT>
<TR>
<TD vAlign=top>
<FORM action=post.php?forum_id=11 method=post name=form
onsubmit="return check_com()">
<TABLE align=center border=0 cellPadding=4 cellSpacing=0 width=100%>
<TBODY>
<TR>
<TD mypic/icon1.gif"
width=18><INPUT name=icon type=radio value=2> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon2.gif"
width=18><INPUT name=icon type=radio value=3> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon3.gif"
width=18><INPUT name=icon type=radio value=4> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon4.gif"
width=18><INPUT name=icon type=radio value=5> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon5.gif"
width=18><INPUT name=icon type=radio value=6> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon6.gif"
width=18><INPUT name=icon type=radio value=7> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon7.gif"
width=18><BR><INPUT name=icon type=radio value=8> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon8.gif"
width=18><INPUT name=icon type=radio value=9> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon9.gif"
width=18><INPUT name=icon type=radio value=10> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon10.gif"
width=18><INPUT name=icon type=radio value=11> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon11.gif"
width=18><INPUT name=icon type=radio value=12> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon12.gif"
width=18><INPUT name=icon type=radio value=13> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon13.gif"
width=18><INPUT name=icon type=radio value=14> <IMG
align=ABSCENTER height=18
src="/blog_article/mypic/icon14.gif"
width=18></TD></TR>
<TR>
<TD return checkSubmit()" type=submit value=" 发 表 ">
<INPUT name=reset type=reset value=" 清 除 "> </TD></TR>
</TBODY></TABLE></FORM></TD></TR>
</TBODY></TABLE>
</FORM>
</html>
【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】
[2]在PHP3中实现SESSION的功能(一)
来源: 互联网 发布时间: 2013-11-30
SESSION函数库:session.inc.php3
<?php
if (!isset($__session_inc__)){
$__session_inc__=1;
//require("cookie.inc.php3");
# -------------------------------------------------------------------
# Session Management v1.0 21.6.1998
# (c) Wild Karl Heinz <kh.wild@wicom.at>
#
# This Include handle Session based variable handling
#
# Please feel free and use it. If you make it more functional
# it would be nice to send me a copy.
#
# Don't forget - Mysql_connect !
#
# The database structure
# Table structure for table 'session'
#
# CREATE TABLE session (
# id int(11) DEFAULT '0' NOT NULL auto_increment,
# sid varchar(20) DEFAULT '' NOT NULL,
# val blob,
# times timestamp(14),
# PRIMARY KEY (id),
# KEY sid (sid),
# UNIQUE sid_2 (sid)
# );
#
# You'll miss here a cron job to delete the old sessions from db
# -------------------------------------------------------------------
// 请注意上面被注释掉的CREATE TABLE语句,
// 你需要在你所使用的数据库上执行这条语句,
// 表名也可以不是session,那么就需要设置下面的$sess_table变量了。
// 此处你需要设置库名,和表名。
// 不过一般建议就使用session作为表名
$sess_db = 'dbname';
$sess_table = 'session';
# ----------------------------------------------------
# Session_CheckID - 检查、设置并返回 Session-ID
# 参数......: cookie保存时间(以分钟计)
# 也可不设置表示这个 cookie 只在当前session 有效
# 这其实就象ASP中SESSION的时效一样。
# 返回值....: 一个唯一的Session-ID (作为cookie存储)
# ----------------------------------------------------
function Session_CheckID( $min )
{
global $sess_sid;
if( !$sess_sid ) {
$sess_sid = uniqid( SC ); //取得一个唯一的随机数
/*
if( $min > 0 ) {
SetCookie("sess_sid", $sess_sid, time()+($min*60), "/", "", 0 );
}
else {
SetCookie("sess_sid", $sess_sid, "", "/", "", 0 );
}
上面是原先的代码,会出错。所以另外用了一个更好的函数。
函数库:cookie.inc.php3
*/
jssetcookie("sess_sid",$sess_sid,$min);
return( false );
}
else {
return( true );
}
}
# ----------------------------------------------------------
# str2arr - 将字符串转换成session数组
# 参数.....: string
# 返回值...: 全局数组(其实就是session)
#本函数用途:将字符串转换成session数组
#如"session[username]=yourid&session[userpass]=12345"
#将会被转换成下面的数组
# session[username]="yourid"
# session[userpass]="12345"
#请注意函数split(),each(),list(),eval()的用法。
# ----------------------------------------------------------
function str2arr( $ts )
{
global $session;
$vals = split( "&", $ts );
while( list($key,$val) = each($vals) ) {
list( $name, $wert ) = split( "=", $val );
if( $val ) eval( "$$name = "$wert";" );
}
}
# ----------------------------------------------------------
# session_read() - 从SESSION表中取数据,转换成session数组
# 参数........: 无
# 返回值......: 如果读出数据,返回 true ,否则返回 false
#注意.........: 用到了str2arr()这个函数
# ----------------------------------------------------------
function session_read()
{
# Hash array to keep session-variables
global $session;
global $sess_sid, $sess_db, $sess_table, $sess_error;
$sel = "Select val from $sess_table where sid = '$sess_sid'";
$res = mysql_db_query( $sess_db, $sel );
if( mysql_numrows( $res ) ) {
$val = mysql_result( $res, 0, "val" );
str2arr( $val );
mysql_free_result( $res );
return( true );
}
else {
return( false );
$sess_error = mysql_error();
}
}
# ------------------------------------------------------
# Split_Array() - 将session数组转换成字符串
# 参数.......: 数组
# 返回值.....: 数组转换得来的字符串
#
# Thanks to Rasmus (这人好象是PHP的发明人)
# 注意:将session数组转换成字符串
#如session[username]="yourid"
# session[userpass]="12345"
#将会被转换成"session[username]=yourid&session[userpass]=12345"
#同时该函数考虑到了数组的某个元素也是数据的情况
#这个函数被设计成一个递归函数
# ------------------------------------------------------
function Split_Array( $arr, $a = "", $b = "", $c = "" )
{
while( list( $key, $val ) = each( $arr ) ) {
if( is_array( $val ) ) {
$ts .= Split_Array( $arr[ $key ],
( strlen( $a ) ? $a : $key ),
( strlen( $b ) ? $b : ( strlen( $a ) ? $key : "" ) ),
( strlen( $c ) ? $c : ( strlen( $b ) ? $key : "" ) ) );
}
else {
$ts .= "session";
$ts .= $a ? "[$a]" : "";
$ts .= $b ? "[$b]" : "";
$ts .= $c ? "[$c]" : "";
$ts .= "[$key]=$val&";
}
}
return( $ts );
}
# ---------------------------------------------------
# session_write - 将session数组转换成字符串,再存到session表中
# 参数.: 无
# 返回值...: 如果存入正常返回 true ,否则返回 false
# ---------------------------------------------------
function session_write()
{
# Hash array to keep session-variables
global $session;
global $sess_sid, $sess_db, $sess_table;
global $sess_error;
# if you like to delete a session-cookie
# you must check it before writting the session
# array
if( !$sess_sid ) { session_checkid( 0 ); }
$ts = Split_Array( $session );
if( $ts > "" ) { $ts = substr( $ts, 0, strlen( $ts ) - 1 ); }
$res = mysql_db_query( $sess_db, "Select * from session where sid = '$sess_s'");
if( mysql_numrows( $res ) == 0 ) {
$sel = "Insert into $sess_table ( id, sid, val, times ) ";
$sel .= "values( 0, '$sess_sid', '$ts', NULL )";
}
else {
$sel = "Update $sess_table set val = '$ts', ";
$sel .= "times = NULL where sid = '$sess_sid'";
}
if( !mysql_db_query( $sess_db, $sel ) ) {
$sess_error = mysql_error();
return( false );
}
else { return( true ); }
}
# ---------------------------------------------
# session_del - 清除当前所有的session
# 并删除session表中和当前session有关的记录
# 参数.....: 一个随机的session id
# 返回值...: 无
# ---------------------------------------------
function session_del()
{
global $session, $sess_db, $sess_table, $sess_sid;
$sel = "Delete from $sess_table where sid = '$sess_sid'";
if( !mysql_db_query( $sess_db, $sel ) ) {
$sess_error = mysql_error();
}
$sess_sid = '';
}
}
?>
原作者:不详
<?php
if (!isset($__session_inc__)){
$__session_inc__=1;
//require("cookie.inc.php3");
# -------------------------------------------------------------------
# Session Management v1.0 21.6.1998
# (c) Wild Karl Heinz <kh.wild@wicom.at>
#
# This Include handle Session based variable handling
#
# Please feel free and use it. If you make it more functional
# it would be nice to send me a copy.
#
# Don't forget - Mysql_connect !
#
# The database structure
# Table structure for table 'session'
#
# CREATE TABLE session (
# id int(11) DEFAULT '0' NOT NULL auto_increment,
# sid varchar(20) DEFAULT '' NOT NULL,
# val blob,
# times timestamp(14),
# PRIMARY KEY (id),
# KEY sid (sid),
# UNIQUE sid_2 (sid)
# );
#
# You'll miss here a cron job to delete the old sessions from db
# -------------------------------------------------------------------
// 请注意上面被注释掉的CREATE TABLE语句,
// 你需要在你所使用的数据库上执行这条语句,
// 表名也可以不是session,那么就需要设置下面的$sess_table变量了。
// 此处你需要设置库名,和表名。
// 不过一般建议就使用session作为表名
$sess_db = 'dbname';
$sess_table = 'session';
# ----------------------------------------------------
# Session_CheckID - 检查、设置并返回 Session-ID
# 参数......: cookie保存时间(以分钟计)
# 也可不设置表示这个 cookie 只在当前session 有效
# 这其实就象ASP中SESSION的时效一样。
# 返回值....: 一个唯一的Session-ID (作为cookie存储)
# ----------------------------------------------------
function Session_CheckID( $min )
{
global $sess_sid;
if( !$sess_sid ) {
$sess_sid = uniqid( SC ); //取得一个唯一的随机数
/*
if( $min > 0 ) {
SetCookie("sess_sid", $sess_sid, time()+($min*60), "/", "", 0 );
}
else {
SetCookie("sess_sid", $sess_sid, "", "/", "", 0 );
}
上面是原先的代码,会出错。所以另外用了一个更好的函数。
函数库:cookie.inc.php3
*/
jssetcookie("sess_sid",$sess_sid,$min);
return( false );
}
else {
return( true );
}
}
# ----------------------------------------------------------
# str2arr - 将字符串转换成session数组
# 参数.....: string
# 返回值...: 全局数组(其实就是session)
#本函数用途:将字符串转换成session数组
#如"session[username]=yourid&session[userpass]=12345"
#将会被转换成下面的数组
# session[username]="yourid"
# session[userpass]="12345"
#请注意函数split(),each(),list(),eval()的用法。
# ----------------------------------------------------------
function str2arr( $ts )
{
global $session;
$vals = split( "&", $ts );
while( list($key,$val) = each($vals) ) {
list( $name, $wert ) = split( "=", $val );
if( $val ) eval( "$$name = "$wert";" );
}
}
# ----------------------------------------------------------
# session_read() - 从SESSION表中取数据,转换成session数组
# 参数........: 无
# 返回值......: 如果读出数据,返回 true ,否则返回 false
#注意.........: 用到了str2arr()这个函数
# ----------------------------------------------------------
function session_read()
{
# Hash array to keep session-variables
global $session;
global $sess_sid, $sess_db, $sess_table, $sess_error;
$sel = "Select val from $sess_table where sid = '$sess_sid'";
$res = mysql_db_query( $sess_db, $sel );
if( mysql_numrows( $res ) ) {
$val = mysql_result( $res, 0, "val" );
str2arr( $val );
mysql_free_result( $res );
return( true );
}
else {
return( false );
$sess_error = mysql_error();
}
}
# ------------------------------------------------------
# Split_Array() - 将session数组转换成字符串
# 参数.......: 数组
# 返回值.....: 数组转换得来的字符串
#
# Thanks to Rasmus (这人好象是PHP的发明人)
# 注意:将session数组转换成字符串
#如session[username]="yourid"
# session[userpass]="12345"
#将会被转换成"session[username]=yourid&session[userpass]=12345"
#同时该函数考虑到了数组的某个元素也是数据的情况
#这个函数被设计成一个递归函数
# ------------------------------------------------------
function Split_Array( $arr, $a = "", $b = "", $c = "" )
{
while( list( $key, $val ) = each( $arr ) ) {
if( is_array( $val ) ) {
$ts .= Split_Array( $arr[ $key ],
( strlen( $a ) ? $a : $key ),
( strlen( $b ) ? $b : ( strlen( $a ) ? $key : "" ) ),
( strlen( $c ) ? $c : ( strlen( $b ) ? $key : "" ) ) );
}
else {
$ts .= "session";
$ts .= $a ? "[$a]" : "";
$ts .= $b ? "[$b]" : "";
$ts .= $c ? "[$c]" : "";
$ts .= "[$key]=$val&";
}
}
return( $ts );
}
# ---------------------------------------------------
# session_write - 将session数组转换成字符串,再存到session表中
# 参数.: 无
# 返回值...: 如果存入正常返回 true ,否则返回 false
# ---------------------------------------------------
function session_write()
{
# Hash array to keep session-variables
global $session;
global $sess_sid, $sess_db, $sess_table;
global $sess_error;
# if you like to delete a session-cookie
# you must check it before writting the session
# array
if( !$sess_sid ) { session_checkid( 0 ); }
$ts = Split_Array( $session );
if( $ts > "" ) { $ts = substr( $ts, 0, strlen( $ts ) - 1 ); }
$res = mysql_db_query( $sess_db, "Select * from session where sid = '$sess_s'");
if( mysql_numrows( $res ) == 0 ) {
$sel = "Insert into $sess_table ( id, sid, val, times ) ";
$sel .= "values( 0, '$sess_sid', '$ts', NULL )";
}
else {
$sel = "Update $sess_table set val = '$ts', ";
$sel .= "times = NULL where sid = '$sess_sid'";
}
if( !mysql_db_query( $sess_db, $sel ) ) {
$sess_error = mysql_error();
return( false );
}
else { return( true ); }
}
# ---------------------------------------------
# session_del - 清除当前所有的session
# 并删除session表中和当前session有关的记录
# 参数.....: 一个随机的session id
# 返回值...: 无
# ---------------------------------------------
function session_del()
{
global $session, $sess_db, $sess_table, $sess_sid;
$sel = "Delete from $sess_table where sid = '$sess_sid'";
if( !mysql_db_query( $sess_db, $sel ) ) {
$sess_error = mysql_error();
}
$sess_sid = '';
}
}
?>
原作者:不详
[3]我用php+mysql写的留言本
来源: 互联网 发布时间: 2013-11-30
guestbook.php:
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<STYLE>A:link {
COLOR: #002878; TEXT-DECORATION: none
}
A:visited {
COLOR: #002878; TEXT-DECORATION: none
}
A:active {
TEXT-DECORATION: none
}
A:hover {
COLOR: #cc1111; TEXT-DECORATION: none
}
P {
COLOR: #002878; FONT-SIZE: 9pt
}
TABLE {
COLOR: #002878; FONT-SIZE: 9pt
}
LI {
COLOR: #002878; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt
}
UL {
COLOR: #002878; FONT-SIZE: 9pt
}
}
</STYLE>
</head>
<body>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="574" height="312">
</center>
<tr>
<td><p align="center">高三<6>班留言本本</br></td>
</tr>
<tr>
<td width="574" height="272" valign="top">
<form method="POST" action="/blog_article/ly.html">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<center>
<tr>
<td width="26%" align="right">
姓名:</td>
<td width="74%"><input
type="text" name="T1" size="13"></td>
</tr>
<tr>
<td width="26%" align="right">
EMAIL:</td>
<td width="74%"><input name="T2" size="13"></td>
</tr>
<tr>
<td width="26%" align="right">
个人主页:</td>
<td width="74%"><input name="T3" size="13" value="http://"></td>
</tr>
<tr>
<td width="26%" align="right">
主题:</td>
<td width="74%"><input name="T4" size="13"></td>
</tr>
<tr>
<td width="26%" align="right" valign="top">
留言:</td>
<td width="74%"><textarea rows="10" name="S1" cols="45" ></textarea></td>
</tr>
<tr>
<td width="100%" align="right" colspan="2">
</td>
</tr>
</table>
<p align="center">
<input type="submit" value="提交" name="B1"> <input type="reset" value="重写" name="B2"></p>
</form>
</center>
</td>
</tr>
</table>
<hr size='1' color='#6666FF'>
</div>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="603" height="294">
<tr>
<td width="603" height="294">
<?
include ("connect.rec");
$qh=mysql_query("SELECT COUNT(*) AS rcnt FROM guestbook");
$data=mysql_fetch_array($qh);
$nr=$data["rcnt"];
//判断偏移量参数是否传递给了脚本,如果没有就使用默认值0
if (empty($offset))
{
$offset=0;
}
//查询结果(这里是每页20条,但你自己完全可以改变它)
//$result=mysql_query("SELECT * from guestbook ORDER BY time desc LIMIT $offset, 5");
$result=mysql_query("SELECT * from guestbook LIMIT $offset, 5");
//显示返回的5条记录
while ($data=mysql_fetch_array($result))
{
printf("姓名:<font color='#000000'>%s</font><br>",$data["name"]);
printf("EMAIL:<font color='#3366FF'>%s</font><br>",$data["mail"]);
printf("个人主页:<font color='#3366FF'>%s</font><br>",$data["url"]);
printf("来自:<font color='#3366FF'>%s</font><br>",$data["ip"]);
printf("留言时间:<font color='#3366FF'>%s</font><br>",$data["time"]);
printf("主题:<font color='#3366FF'>%s</font><br>",$data["title"]);
printf("内容:<font color='#000000'>%s</font><br>",$data["ly"]);
printf("<hr size='1' color='#6666FF'>");
}
//下一步,要写出到其它页面的链接
if($offset) //如果偏移量是0,不显示前一页的链接
{
$preoffset=$offset-5;
print "<a href="/blog_article/$PHP_SELF/offset/$preoffset.html">前一页</a> n";
}
//计算总共需要的页数
$pages=ceil($nr/5); //$pages变量现在包含所需的页数
for ($i=1; $i <= $pages; $i++)
{
$newoffset=5*$i-5;
print "<a href="/blog_article/$PHP_SELF/offset/$newoffset.html">$i</a> n";
}
//检查是否是最后一页
$next = $offset+5;
if ($next<$nr)
{
print "<a href="/blog_article/$PHP_SELF/offset/$next.html">下一页</a> n";
}
printf("<a href='javascript:history.back()'>返回</a>")
?>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>
ly.php:
<?
include ("connect.rec");
$name = $T1;
$mail = $T2;
$url = $T3;
$title = $T4;
$time = date( "Y-m-j H:i:s" );
$ip = getenv("REMOTE_ADDR");
$ly = $S1;
$result = mysql_query("insert into guestbook (name,mail,url,ip,time,title,ly) values ('$name','$mail','$url','$ip','$time','$title','$ly')");
if ($result == 1)
{
echo("留言成功!");
printf("<script language='javascript'>");
printf("location='guestbook.php'");
printf("</script>");
}
else
{
echo("留言失败!");
printf("<a href='javascript:history.back()'>返回</a>");
}
?>
可到http://xinai.oso.com.cn/class/guesttap.php查看
【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<STYLE>A:link {
COLOR: #002878; TEXT-DECORATION: none
}
A:visited {
COLOR: #002878; TEXT-DECORATION: none
}
A:active {
TEXT-DECORATION: none
}
A:hover {
COLOR: #cc1111; TEXT-DECORATION: none
}
P {
COLOR: #002878; FONT-SIZE: 9pt
}
TABLE {
COLOR: #002878; FONT-SIZE: 9pt
}
LI {
COLOR: #002878; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt
}
UL {
COLOR: #002878; FONT-SIZE: 9pt
}
}
</STYLE>
</head>
<body>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="574" height="312">
</center>
<tr>
<td><p align="center">高三<6>班留言本本</br></td>
</tr>
<tr>
<td width="574" height="272" valign="top">
<form method="POST" action="/blog_article/ly.html">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<center>
<tr>
<td width="26%" align="right">
姓名:</td>
<td width="74%"><input
type="text" name="T1" size="13"></td>
</tr>
<tr>
<td width="26%" align="right">
EMAIL:</td>
<td width="74%"><input name="T2" size="13"></td>
</tr>
<tr>
<td width="26%" align="right">
个人主页:</td>
<td width="74%"><input name="T3" size="13" value="http://"></td>
</tr>
<tr>
<td width="26%" align="right">
主题:</td>
<td width="74%"><input name="T4" size="13"></td>
</tr>
<tr>
<td width="26%" align="right" valign="top">
留言:</td>
<td width="74%"><textarea rows="10" name="S1" cols="45" ></textarea></td>
</tr>
<tr>
<td width="100%" align="right" colspan="2">
</td>
</tr>
</table>
<p align="center">
<input type="submit" value="提交" name="B1"> <input type="reset" value="重写" name="B2"></p>
</form>
</center>
</td>
</tr>
</table>
<hr size='1' color='#6666FF'>
</div>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="603" height="294">
<tr>
<td width="603" height="294">
<?
include ("connect.rec");
$qh=mysql_query("SELECT COUNT(*) AS rcnt FROM guestbook");
$data=mysql_fetch_array($qh);
$nr=$data["rcnt"];
//判断偏移量参数是否传递给了脚本,如果没有就使用默认值0
if (empty($offset))
{
$offset=0;
}
//查询结果(这里是每页20条,但你自己完全可以改变它)
//$result=mysql_query("SELECT * from guestbook ORDER BY time desc LIMIT $offset, 5");
$result=mysql_query("SELECT * from guestbook LIMIT $offset, 5");
//显示返回的5条记录
while ($data=mysql_fetch_array($result))
{
printf("姓名:<font color='#000000'>%s</font><br>",$data["name"]);
printf("EMAIL:<font color='#3366FF'>%s</font><br>",$data["mail"]);
printf("个人主页:<font color='#3366FF'>%s</font><br>",$data["url"]);
printf("来自:<font color='#3366FF'>%s</font><br>",$data["ip"]);
printf("留言时间:<font color='#3366FF'>%s</font><br>",$data["time"]);
printf("主题:<font color='#3366FF'>%s</font><br>",$data["title"]);
printf("内容:<font color='#000000'>%s</font><br>",$data["ly"]);
printf("<hr size='1' color='#6666FF'>");
}
//下一步,要写出到其它页面的链接
if($offset) //如果偏移量是0,不显示前一页的链接
{
$preoffset=$offset-5;
print "<a href="/blog_article/$PHP_SELF/offset/$preoffset.html">前一页</a> n";
}
//计算总共需要的页数
$pages=ceil($nr/5); //$pages变量现在包含所需的页数
for ($i=1; $i <= $pages; $i++)
{
$newoffset=5*$i-5;
print "<a href="/blog_article/$PHP_SELF/offset/$newoffset.html">$i</a> n";
}
//检查是否是最后一页
$next = $offset+5;
if ($next<$nr)
{
print "<a href="/blog_article/$PHP_SELF/offset/$next.html">下一页</a> n";
}
printf("<a href='javascript:history.back()'>返回</a>")
?>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>
ly.php:
<?
include ("connect.rec");
$name = $T1;
$mail = $T2;
$url = $T3;
$title = $T4;
$time = date( "Y-m-j H:i:s" );
$ip = getenv("REMOTE_ADDR");
$ly = $S1;
$result = mysql_query("insert into guestbook (name,mail,url,ip,time,title,ly) values ('$name','$mail','$url','$ip','$time','$title','$ly')");
if ($result == 1)
{
echo("留言成功!");
printf("<script language='javascript'>");
printf("location='guestbook.php'");
printf("</script>");
}
else
{
echo("留言失败!");
printf("<a href='javascript:history.back()'>返回</a>");
}
?>
可到http://xinai.oso.com.cn/class/guesttap.php查看
【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】
最新技术文章: