一个没有MYSQL数据库支持的简易留言本的编写
由于国内MySQL资源比较紧张,国外的不是太慢,就是不对我国用户开放。因此,在没有MYSQL的日子里,我们想做一些方便他人和完善自己站点的事情,那简直比登天还难,为了摆脱这种痛苦,niky哭思冥想,闭门造车,终于,皇天不负有心人,一个不需要MYSQL数据库支持的简易留言本就这样出台了,我们暂且叫它gbook.php吧,源程序如下:
if ($message)
{
$message = ereg_replace( "rnrn", "n
", $message);
//去除无效的控制符号
$date = date( "l, F j Y, h:i a"); //获取指定的日期时间格式
$ip=getenv("REMOTE_ADDR");
$message = "
$name | 写于--$date | 来自>>$ip | |
$subject | |||
$massage |
";
$fp = fopen (basename($PHP_SELF) . ".comment", "a");
fwrite ($fp, $message);
fclose ($fp);
}
@readfile(basename(($PHP_SELF . ".comment")));
//读出记录文件内容
?>
──────────────────────────────────────
上面的程序,其原理是:在PHP端首先判断message变量是否存在,如果不存在,则读文件。读文件使用了readfile函数。至于文件名的提取,这里使用了一个巧妙的方式(使用$PHP_SELF变量提取文件所在的绝对位置,然后用basename()函数提取文件名,再加上指定的文件尾comment.)来完成的。为了能更好的学习PHP&MySQL,特拿来和大家共享,也希望曾经和niky一样痛苦过的网路人能有一个属于自己的留言本,而不是"xxx留言本由xxx.com提供."而大煞风景。还等什么,赶快行动吧!
版权所有,请勿随便转载!
Copyright ©2000 niky All rights reserved.
【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools