Is it possible to use GET and argv at the same time in php?
phpcn_u1582
phpcn_u1582 2017-05-18 10:47:35
0
5
522

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_u1582
phpcn_u1582

reply all(5)
阿神

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

黄舟

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

曾经蜡笔没有小新

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.

世界只因有你

$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!

仅有的幸福

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template