如何从$_GET使版本变量安全


how to make version variable secure from $_GET

我有page?vesion=1.0.1

我如何通过这样的东西使$_GET["版本"]安全

$version = (float) $_GET['version'];

但如果它是1.2或1.0,这将起作用,如果它是1.0.1 ,这将不起作用

使用诸如/[0-9]+('.[0-9]+){0,3}/之类的正则表达式对其进行验证。preg_match是您的朋友:

if (preg_match('/[0-9]+('.[0-9]+){0,3}/', $_GET['version'], $match)) {
    // $match[0] contains the validated version number
}

如果我清楚地知道你想接受什么,拒绝什么,我可以帮你更多。

edit:将正则表达式中的3替换为辅助版本号;允许使用3 0.1.2.3,但0.1.2.3.4不是