php get variables as key with no value assigned

前端 未结 5 1535
执笔经年
执笔经年 2021-01-12 11:45

If I enter the following into the browser:

   http://domain.com/script.php?1234

And script.php has the following script:

           


        
5条回答
  •  离开以前
    2021-01-12 11:54

    My question is, is this officially correct or it's poor programming?

    Query-parameter-without-value is not documented to work, though it probably will continue to in practice.

    If you just want to grab the whole query string without parsing it as parameters, the best thing to do would be to say so directly:

    echo $_SERVER['QUERY_STRING']
    

    (Whatever you do, don't echo it directly though! Either sanitise the value by eg. converting it to an integer, or, if you want to allow an arbitrary string, output it escaped suitably for JavaScript, by backslash-escaping quotes and backslashes.)

提交回复
热议问题