PHP $ _GET安全性,$ _POST安全性最佳实践 [英] PHP $_GET security, $_POST security best practice

查看:196
本文介绍了PHP $ _GET安全性,$ _POST安全性最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个很好的主题,但是我想在几种不同的情况下对使用用户变量数据的方法进行确认。


  1. 该变量从不在数据库中使用,从不存储,只显示在用户的屏幕上。

  2. 变量被带入数据库并用于SQL查询。

  3. 该变量同时具有这两种功能。那一刻我xss_clean和strip_tags。我一直都是这样做的,只是通过自动驾驶仪。有更好的技术吗?道歉,如果有一个相同的问题。我有点假设有,虽然我找不到像这样彻底。



    干杯。

    解决方案


    1. 在HTML上下文中输出时使用适当的函数,它是 htmlspecialchars

    2. 使用预处理语句

    3. 请参阅1.和2. - 取决于您是在显示变量还是在查询中使用它。


    It's a well covered topic, but I'd like to get some confirmation on methods of using data from user variables, in a few different situations.

    1. The variable is never used in a database, never stored, only displayed on screen for the user. Which function to use to make sure no html or javascript can screw things up?

    2. The variable is taken into the database, and used in SQL queries.

    3. The variable does both.

    At the moment I xss_clean, and strip_tags. I've always done this, just by autopilot. Is there a better technique? Apologies if there's an identical question out there. I kinda assume there is, although I couldn't find one as thorough as this.

    Cheers.

    解决方案

    1. Use the appropriate function while outputting, in HTML context, this is htmlspecialchars
    2. Use prepared statements
    3. See 1. and 2. – depending on whether you are displaying the variable or you are using it in a query.

    这篇关于PHP $ _GET安全性,$ _POST安全性最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆