Heim  >  Artikel  >  php教程  >  php制作文本式留言板

php制作文本式留言板

WBOY
WBOYOriginal
2016-06-06 20:06:281374Durchsuche

本文给大家分享的是使用php结合文本文件制作的留言板的代码,非常简单,实现了常用的功能,推荐给大家,有需要的小伙伴参考下吧。

代码很简单,就不多废话了,直接奉上代码:

del.php

复制代码 代码如下:





我的留言板



   
   

删除留言


        $id=$_GET["id"];
    $info=file_get_contents("liuyan.txt");
    $lylist=explode("@@@", $info);
    unset($lylist[$id]);
    $ninfo=implode("@@@", $lylist);
    file_put_contents("liuyan.txt", $ninfo);
     $alert="alert('删除成功!')";
     echo "<script>".$alert."</script>";
    ?>



doAdd.php

复制代码 代码如下:





我的留言板



   
   

添加留言


        //获取留言板的信息
    $title=$_POST["title"];
    $author=$_POST["author"];
    $content=$_POST["content"];
    $time=time();
    $ip=$_SERVER["REMOTE_ADDR"];
    $ly="{$title}##{$author}##{$content}##{$time}##{$ip}@@@";
    echo $ly;
    $ly=$ly.file_get_contents("liuyan.txt");
    file_put_contents("liuyan.txt",$ly);
    $alert="alert('留言成功!谢谢!')";
    echo "<script>".$alert."</script>;"
    ?>  



index.php

复制代码 代码如下:





我的留言板



   
   

添加留言


   

   
   
       
       
   
   
       
       
   
   
       
       
   
   
       
   
   
标题:
留言者:
留言内容:

                  
       
       

   




liuyan.txt

复制代码 代码如下:


安神######1426588557##127.0.0.1@@@

show.php

复制代码 代码如下:





我的留言板



   
   

添加留言


   
       
           
           
           
           
           
           
       
                $info=file_get_contents("liuyan.txt");
        if($info==null){
            $alert="alert('无留言信息!')";
            echo "<script>".$alert."</script>";
        }
        else{
            $info=rtrim($info,"@");
        $lylist=explode( "@@@",$info);
        foreach ($lylist as $key=>$v) {
            $ly=explode("##",$v );
            echo "";
            echo "";
            echo "";
            echo "";
            echo "";
            echo "";
            echo "";
            echo "";
        }
        }
        ?>
   
留言标题 留言人 留言内容 留言时间 IP地址 操作
$ly[0]$ly[1]$ly[2]".date("Y-m-d H:i:s",$ly[3]+8*3600)."$ly[4]删除




menu.php

复制代码 代码如下:

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn