dras2334 2013-05-06 11:20
浏览 244

如何使用Markdown和MySQL?

I want my users to be able to comment using Markdown and avoiding XSS.

What is the correct sequence of actions to do ?

This is my understanding of how it works:

user input via HTML form using Markdown syntax
$Input = markdown(mysql_real_escape_string($_POST['userInput']));
insert $input into database

And then, Do I need also to use htmlspecialchars ?

  • 写回答

2条回答 默认 最新

  • dongshanni1611 2013-05-06 11:23
    关注

    mysql_real_escape_string is used to avoid SQL INJECTION. Because it escapes SQL.

    XSS can be avoided using strip_tags(), preg_match() and htmlspecialchars() together

    XSS is based on html tags that contains exploits. For example scripts in java script, or redirections, or opening files in tags.

    strip_tags() removes html tags. Also there is one more interesting function called

    htmlspecialchars() for preventing XSS.

    The most imporant things to prevent sql injection attack

    1. Data Validation using preg_match
    2. Data Sanitization using strip_tags
    3. Output Escaping using htmlspecialchars

    so first you should validate data, then sanitize it and finally escape it using htmlspecialchars.

    评论

报告相同问题?

悬赏问题

  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题