Home > php教程 > php手册 > body text

一个没有MYSQL数据库支持的简易留言本的编写

WBOY
Release: 2016-06-13 12:38:04
Original
888 people have browsed it

由于国内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 $email 写于--$date 来自>>$ip
$subject
$massage

       

";
    $fp = fopen (basename($PHP_SELF) .  ".comment",  "a");
    fwrite ($fp, $message);
    fclose ($fp);
    }
@readfile(basename(($PHP_SELF .  ".comment")));
//读出记录文件内容
?>

  

姓名: E-mail:


       
  主题:
  

      
您想说的话:


     
           
  

  
      
──────────────────────────────────────
   上面的程序,其原理是:在PHP端首先判断message变量是否存在,如果不存在,则读文件。读文件使用了readfile函数。至于文件名的提取,这里使用了一个巧妙的方式(使用$PHP_SELF变量提取文件所在的绝对位置,然后用basename()函数提取文件名,再加上指定的文件尾comment.)来完成的。为了能更好的学习PHP&MySQL,特拿来和大家共享,也希望曾经和niky一样痛苦过的网路人能有一个属于自己的留言本,而不是"xxx留言本由xxx.com提供."而大煞风景。还等什么,赶快行动吧!
                    版权所有,请勿随便转载!
        Copyright ©2000   niky   All rights reserved.  

【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】    
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!