首页 > 编程技术 > php

php+dbfile开发小型留言本

发布时间:2016-11-25 17:36

board.php用来存储数据,可以先在里面添加了一条留言纪录。
代码
<?php
$Board=array(
array(1081410332,'测试','测试留言本','http://www.piscdong.com')
);
?>
index.php是留言显示和提交页面。
代码
<?php
require_once('board.php');
function htmlencode($content){
$content=htmlspecialchars($content);
$content=preg_replace("//i","<br />",$content);
return $content;
}
if($HTTP_SERVER_VARS['REQUEST_METHOD']=='POST'){
$configpath_parts1 = pathinfo($SCRIPT_FILENAME);
$time=time();
$name=$HTTP_POST_VARS['name'];
$url=(preg_match("/^[w-]+(.[w-]+)*@[w-]+(.[w-]+)+$/i",$HTTP_POST_VARS['url']) || $HTTP_POST_VARS['url']=='')?$HTTP_POST_VARS['url']:'http://'.htmlspecialchars(preg_replace("/https?:///i",'',$HTTP_POST_VARS['url']),ENT_QUOTES);
$info=htmlencode($HTTP_POST_VARS['info']);
if($name!='' && $info!=''){
$Board[]=array($time,$name,$info,$url);
}
for($i=0;$i<count($Board);$i++){
$bd=current($Board);
$s[]=" array(".$bd[0].",'".$bd[1]."','".$bd[2]."','".$bd[3]."')";
next($Board);
}
$content="<?php $Board=array( ".join($s,", ")." ); ?>";
$filename=$configpath_parts1['dirname'].'/'.'board.php';
if(is_writable($filename) || !file_exists($filename)){
if(!$handle=fopen($filename,'w')){
return false;
}
if(!fwrite($handle,$content)){
return false;
}
fclose($handle);
}else{
return false;
}
header('Location:.');
}else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>留言本</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<form method="post" name="form1" action="">
<table border="0" cellspacing="5" cellpadding="0" align="center">
<?php require("cookie.inc.php3") ; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>Untitled</title>
</head>
<body>
<P>在网页的任何地方设置cookie
<?php
if (!$show){
    $username="liubing";
    jssetcookie("username","liubing",1);
    echo "<p>cookie username 被设置成    $username<br>";
    echo "有效期1分钟<br>" ;
    echo "<a href='$PATH_INFO?show=1'> 试一下cookiee 有没有起作用</a>" ;
}
else{
    echo "<p>读到的cookie username 值为: $username<br>";
    echo "有效期1分钟,1分钟后再刷新本页面就会看不到了<br>" ;
</a>" ;
}
?>
</body>
</html>

在安装了一些第三方函数库之后,结合图形处理技能,你就可以迅速使用PHP创建和处理图像了。事实上,你也不需要很多几何学知识——因为我在中学的时候这门功课曾经不及格而现在却能使用PHP创建图像!
在使用基本的图像创建函数之前,需要安装GD库。要使用JPEG相关的图像创建函数还需要安装jpeg-6b。在图像中使用Type 1字体的时候还必须安装t1lib。asdf
在这里,你还需要对你的系统设置进行进一步地调整。首先安装t1lib并结束,然后是jpeg-6b。第三步安装GD函数库。确保以上三部分按顺序安装,原因是你需要编译GD库才能使用jpeg-6b库。如果首先安装jpeg-6b,编译就会出错,这会让你不知所措够上一段时间。
在三函数库之后,重新配置PHP。这是在轻松安装PHP的DSO版本时的典型方法。然后执行make clean,命令,并在当前配置提示中加入以下代码:
--with-gd=[/path/to/gd]
--with-jpeg-dir=[/path/to/jpeg-6b]
--with-t1lib=[/path/to/t1lib]
最后执行make、make install完成配置。重新启动 Apache,并运行phpinfo()函数以检查新功能是否正常运行,然后就可以开始了。
取决于安装的GD库版本,你可能具有创建GIF或者PNG图像的能力。关键是如果你已经安装了gd-1.6或者早期版本,则可处理GIF文件,但不能处理PNG文件;如果安装了gd-1.6或者以后版本,你可以处理PNG文件却又不能处理GIF文件。
创建一个简单的图像需要几个函数。我将按步骤演示如下。
输出包含你所创建图像MIME类型的文件头,本例中为PNG。
header ("Content-type: image/png");
使用ImageCreate()创建一变量存放空白图像。该函数需要一个图片像素尺寸。格式为ImageCreate(x_size, y_size),对250*250像素的图片,如下:
$newImg = ImageCreate(250,250);
由于此时你的图像还是空白,所以需要用某些色彩填满它。但首先需要用ImageColorAllocate()函数按照颜色的RGB值为每种颜色确定名字。函数的格式为ImageColorAllocate([image], [red], [green], [blue])。如是天蓝色,应使用:
$skyblue = ImageColorAllocate($newImg,136,193,255);
接着,用ImageFill()函数为图像填充以上颜色。实际上ImageFill()函数有多个版本,如ImageFillRectangle(), ImageFillPolygon()等等。为简单起见,采用ImageFill()函数进行颜色填充,格式如下:
ImageFill([image], [start x point], [start y point], [color])
ImageFill($newImg,0,0,$skyblue);
抽象类
抽象类不能被实例化。
抽象类与其它类一样,允许定义变量及方法。
抽象类同样可以定义一个抽象的方法,抽象类的方法不会被执行,不过将有可能会在其派生类中执行。
例六:抽象类
<?php
abstract class foo {
protected $x;
abstract function display();
function setX($x) {
$this->x = $x;
}
}
class foo2 extends foo {
function display() {
// Code
}
}
?>
__call
PHP5 的对象新增了一个专用方法 __call(),这个方法用来监视一个对象中的其它方法。如果你试着调用一个对象中不存在的方法,__call 方法将会被自动调用。
例七:__call
<?php
class foo {
function __call($name,$arguments) {
print("Did you call me? I'm $name!");
}
} $x = new foo();
$x->doStuff();
$x->fancy_stuff();
?>
这个特殊的方法可以被用来实现“过载(overloading)”的动作,这样你就可以检查你的参数并且通过调用一个私有的方法来传递参数。
例八:使用 __call 实现“过载”动作
<?php
class Magic {
function __call($name,$arguments) {
if($name=='foo') {
if(is_int($arguments[0])) $this->foo_for_int($arguments[0]);
if(is_string($arguments[0])) $this->foo_for_string($arguments[0]);
}
} private function foo_for_int($x) {
print("oh an int!");
} private function foo_for_string($x) {
print("oh a string!");
}
} $x = new Magic();
$x->foo(3);
$x->foo("3");
?>
__set 和 __get
这是一个很棒的方法,__set 和 __get 方法可以用来捕获一个对象中不存在的变量和方法。
例九: __set 和 __get
<?php
class foo {
function __set($name,$val) {
print("Hello, you tried to put $val in $name");
}
function __get($name) {
print("Hey you asked for $name");
}
}
$x = new foo();
$x->bar = 3;
print($x->winky_winky);
//执行存储过程
for($i=0;$i<$ses_basket_items;$i++)
{
$query="exec add_ddxx
@p_account="$session_account",
@p_name="$name[$i]",
@p_num="$num[$i]",
@p_marketprice="$marketprice[$i]",
@p_memberprice="$memberprice[$i]",
@p_priceoftax="$notaxprice[$i]",
@p_priceoflast="$lastprice[$i]",
@p_sumprice="$price[$i]",
@p_buy_date="$date",
@p_flag="$p_flag"";
$result=mssql_query($query,$connection) or die("存储过程执行错误,无法执行该SQL:$query");
}

标签:[!--infotagslink--]

您可能感兴趣的文章: