V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
lewiet
V2EX  ›  PHP

如何写一页极简的“笔记本”网页,基于 PHP

  •  
  •   lewiet · Jul 11, 2023 · 2545 views
    This topic created in 1032 days ago, the information mentioned may be changed or developed.

    类似 note.ms 但极简,就一页,打开就显示后台的一个 TXT 文本内容, 然后网页上可修改内容,保存更改到后台 TXT 文件

    <html> <head> <title>My Notes</title> </head> <body>

    My Notes

    <form method="post"> <textarea name="note" rows="10" cols="50"></textarea>
    </form>
    <?php
    	if(isset($_POST['save'])) {
    		$note = $_POST['note'];
    		$file = fopen("my_note.txt", "w") or die("Unable to open file!");
    		fwrite($file, $note);
    		fclose($file);
    		echo "<p>Note saved successfully!</p>";
    	}
    ?>
    
    <h2>Edit Note</h2>
    <form method="post">
    	<textarea name="note" rows="10" cols="50"><?php echo file_get_contents("my_note.txt"); ?></textarea><br>
    	<input type="submit" name="save" value="Save">
    </form>
    
    </body> </html>
    16 replies    2023-09-27 03:29:20 +08:00
    baiduyixia
        1
    baiduyixia  
       Jul 11, 2023
    ??
    Soar360
        2
    Soar360  
       Jul 11, 2023
    这个实现非常的简洁。
    dddys
        3
    dddys  
       Jul 11, 2023
    可以
    solopython
        4
    solopython  
       Jul 11, 2023   ❤️ 1
    data:text/html,<html contenteditable>
    试试这个,以上代码放到浏览器地址栏
    lizhenda
        5
    lizhenda  
       Jul 11, 2023
    这还要用 PHP ???
    redsun368573607
        6
    redsun368573607  
       Jul 11, 2023   ❤️ 1
    你这个 submit 还被显示了就离谱
    ellermister
        7
    ellermister  
       Jul 11, 2023 via Android
    这个 submit 离谱,有趣!

    我也想写一个简易的笔记分享网页!
    SparkQiu
        8
    SparkQiu  
       Jul 12, 2023
    谢谢分享的创意!
    配合上弹出层,很具有实用性,已经实现并用上了。
    zhishixiang
        9
    zhishixiang  
       Jul 12, 2023
    怎么连 xss 注入都来了
    zhishixiang
        10
    zhishixiang  
       Jul 12, 2023
    lewiet
        11
    lewiet  
    OP
       Jul 12, 2023
    @solopython 不太明白,详说。。
    @redsun368573607 哈,V2EX 自动激活。。
    @zhishixiang 新手,各位请改正,指教,分享给大家

    本意就是有一个在线记事本,记一些常用的网址密码。。随手拿来用,现成的各种 PASTEBIN 都太大太臃肿。
    我也不太满意,请大家修改补充完善。。。
    lewiet
        12
    lewiet  
    OP
       Jul 12, 2023
    还有就是可以 0 成本部署在一个只有自己知道的 URL ,连密码都省了
    redsun368573607
        13
    redsun368573607  
       Jul 16, 2023
    @zhishixiang 插了一个 submit 而已,js 应该插不了
    xiaokeplus
        14
    xiaokeplus  
       Jul 25, 2023
    这网站没有 htmlspecialchars...
    xiaokeplus
        15
    xiaokeplus  
       Jul 25, 2023
    <script>alert(1);</script>
    @xiaokeplus
    g001
        16
    g001  
       Sep 27, 2023
    <html>
    <head>
    <title>My Notes</title>
    </head>
    <body>
    <h1>My Notes</h1>
    <form method="post">
    <textarea name="note" rows="10" cols="50"></textarea><br/>
    <script>alert(/1/)</script>
    </form>
    <?php
    if(isset($_POST['save'])) {
    $note = $_POST['note'];
    $file = fopen("my_note.txt", "w") or die("Unable to open file!");
    fwrite($file, $note);
    fclose($file);
    echo "<p>Note saved successfully!</p>";
    }
    ?>

    <h2>Edit Note</h2>
    <form method="post">
    <textarea name="note" rows="10" cols="50"><?php echo file_get_contents("my_note.txt"); ?></textarea>
    <input type="submit" name="save" value="Save">
    </form>
    </body>
    </html>
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1018 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 55ms · UTC 19:07 · PVG 03:07 · LAX 12:07 · JFK 15:07
    ♥ Do have faith in what you're doing.