phpはテキスト伝言板を作ります。


コードは簡単です。無駄話は多くないです。直接コードを送ります。
del.php

<html>
<head >
<meta charset="utf-8">
<title> </title>
</head>
<body>
<center>
    <?php include("menu.php"); ?>
    <h3> </h3>
    <?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>";
    ?>
</center>
</body>
</html>
doAdd.php

<html>
<head >
<meta charset="utf-8">
<title> </title>
</head>
<body>
<center>
    <?php include("menu.php"); ?>
    <h3> </h3>
    <?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>;"
    ?>  
</center>
</body>
</html>
index.php

<html>
<head >
<meta charset="utf-8">
<title> </title>
</head>
<body>
<center>
    <?php include("menu.php"); ?>
    <h3> </h3>
    <form action="doAdd.php" method="post">
    <table width="400" >
    <tr>
        <td align="right"> :</td>
        <td><input type="text" name="title"/></td>
    </tr>
    <tr>
        <td align="right"> :</td>
        <td><input type="text" name="author"/></td>
    </tr>
    <tr>
        <td align="right" valign="top"> :</td>
        <td><textarea name="content" rows="5" cols="30"></textarea></td>
    </tr>
    <tr>
        <td colspan="2" align="center">
        <input type="submit" value=" ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="reset" value=" ">
        </td>
    </tr>
    </table>
    </form>
</center>
</body>
</html>
liuyan.txt

######1426588557##127.0.0.1@@@
show.php

<html>
<head >
<meta charset="utf-8">
<title> </title>
</head>
<body>
<center>
    <?php include("menu.php"); ?>
    <h3> </h3>
    <table border="1">
        <tr>
            <th> </th>
            <th> </th>
            <th> </th>
            <th> </th>
            <th>IP </th>
            <th> </th>
        </tr>
        <?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 "<tr>";
            echo "<td aligh='center'>$ly[0]</td>";
            echo "<td aligh='center'>$ly[1]</td>";
            echo "<td aligh='center'>$ly[2]</td>";
            echo "<td>".date("Y-m-d H:i:s",$ly[3]+8*3600)."</td>";
            echo "<td>$ly[4]</td>";
            echo "<td><a href='del.php?id={$key}'> </a></td>";
            echo "</tr>";
        }
        }
        ?>
    </table>
</center>
</body>
</html>
menu.php

<h2 color="blue"> </h2>
    <a href="index.php"> </a>
    <a href="show.php"> </a>
    <hr width="90%"/>
以上述べましたが、本文の内容は全部です。お好きになってください。