search

Home  >  Q&A  >  body text

Is it possible to use GET and argv at the same time in php?

I saw a web application php file written:

$act=$_GET['act'];
if ($act)
{
$act = $argv[1];
}

Full of question marks? ? ?
Can anyone tell me how to use this method? I can’t find it anywhere. . .
Thank you! ! !

phpcn_u1582phpcn_u15822795 days ago533

reply all(5)I'll reply

  • 阿神

    阿神2017-05-18 10:49:35

    Sometimes you can't or don't want to install php-cgi,您没有编辑php文件的选项可以将$_GETset as parameters passed in.

    $act=$_GET['act'];
    if ($act){
        $act = $argv[1];
    }
    

    You can access the variables of your startup script from the $argvarray in your php application. The first entry will be the name of the script they came from

    php -r '$_GET["key"]="value"; require_once("script.php"); 

    This will avoid changing your php文件,并允许您使用plain php命令。如果你安装了php-cgi, be sure to use this

    -r表示在以下字符串中运行php代码。您手动设置$_GET value and then reference the file to run.

    It's worth noting that you should run this file in the correct folder, usually but not always php文件所在的文件夹。Requires the statement will use the location of your command to resolve the relative URL, not the location of the file

    reply
    0
  • 黄舟

    黄舟2017-05-18 10:49:35

    $_GET, generally stores query stringkey=>valuearrays. In principle, it is read-only, but assignment is also possible, but it is not recommended.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-18 10:49:35

    Normally speaking, $_GET and $argv should not appear together. One is for web execution and the other is for command line execution. But after searching just now, it seems that get can be passed through php-cgi. Click here to view.

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-18 10:49:35

    $act=$_GET['act']; is to get the string xxxx after act=xxxx on the url. $act = $argv[1] obtains the second parameter value in the command line.

    The logic of the code here is to first get the parameters from the url, and if the parameters have values, then reassign them. So the last $act of this code is the value of $argv[1]. This php file can only be called from the command line!

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-18 10:49:35

    It is suggested that the poster should change it instead of mixing them. It is recommended to use argv on the command line, get post request, etc. It is better to use them separately.

    reply
    0
  • Cancelreply