V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lewiet
V2EX  ›  PHP

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

  •  
  •   lewiet · 291 天前 · 1501 次点击
    这是一个创建于 291 天前的主题,其中的信息可能已经有所发展或是发生改变。

    类似 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 条回复    2023-09-27 03:29:20 +08:00
    baiduyixia
        1
    baiduyixia  
       290 天前
    ??
    Soar360
        2
    Soar360  
       290 天前
    这个实现非常的简洁。
    dddys
        3
    dddys  
       290 天前
    可以
    solopython
        4
    solopython  
       290 天前   ❤️ 1
    data:text/html,<html contenteditable>
    试试这个,以上代码放到浏览器地址栏
    lizhenda
        5
    lizhenda  
       290 天前
    这还要用 PHP ???
    redsun368573607
        6
    redsun368573607  
       290 天前   ❤️ 1
    你这个 submit 还被显示了就离谱
    ellermister
        7
    ellermister  
       290 天前 via Android
    这个 submit 离谱,有趣!

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

    本意就是有一个在线记事本,记一些常用的网址密码。。随手拿来用,现成的各种 PASTEBIN 都太大太臃肿。
    我也不太满意,请大家修改补充完善。。。
    lewiet
        12
    lewiet  
    OP
       290 天前
    还有就是可以 0 成本部署在一个只有自己知道的 URL ,连密码都省了
    redsun368573607
        13
    redsun368573607  
       286 天前
    @zhishixiang 插了一个 submit 而已,js 应该插不了
    xiaokeplus
        14
    xiaokeplus  
       277 天前
    这网站没有 htmlspecialchars...
    xiaokeplus
        15
    xiaokeplus  
       277 天前
    <script>alert(1);</script>
    @xiaokeplus
    g001
        16
    g001  
       213 天前
    <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>
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2745 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:19 · PVG 18:19 · LAX 03:19 · JFK 06:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.