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! ! !
阿神2017-05-18 10:49:35
Sometimes you can't or don't want to install php-cgi
,您没有编辑php文件的选项可以将$_GET
set as parameters passed in.
$act=$_GET['act'];
if ($act){
$act = $argv[1];
}
You can access the variables of your startup script from the $argv
array 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
黄舟2017-05-18 10:49:35
$_GET, generally stores query string
的key=>value
arrays. In principle, it is read-only, but assignment is also possible, but it is not recommended.
曾经蜡笔没有小新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.
世界只因有你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!
仅有的幸福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.