dongzhao1865 2015-03-08 05:54
浏览 76
已采纳

如何使用JQuery / JavaScript / PHP将文本写入外部文件?

I have some text stored in a POST variable that I need to append to an HTML file. I want to do within my PHP webpage, but it could use HTML, JQuery, Javascript, or anything else that will run natively. I've tried the PHP approach, but it hasn't worked despite my numerous attempts. Always a 500 internal server error. And I can't find anything on writing to files using JQuery, so if anyone out there knows something I don't, it would be appreciated. Thanks :)

  • 写回答

1条回答

  • douzhao7634 2015-03-08 06:04
    关注

    Writing directly to you html/php documents is extremely bad practice. As your comment said you need to validate the input and if you make a mistake you could screw up your whole website.

    There are a couple of options you could use:

    • localstorage: This saves the changes to the browser of the user. This means that the changes wont be on the server. Very easy solution.
    • Add a database: With PHP it is very easy to add a SQL databse. Write some functions that write the data to the database and read the data from there. Safer than writing directly to HTML/PHP but still needs validation
    • Do some extreme reading into all the PHP IO functions. You need some extreme good handling if you want this site live.

    I think that with the DB you`ll manage, just be safe and build in some security

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题