简体   繁体   中英

How to pass command line PHP parameters to a script that is using REQUEST or POST?

I have a script that I can usually access like this:

http://www.example.com/index.php?p1=a1&p2=b1

If I try to do this using shell_exec, how would I pass the arguments in? This doesn't work:

shell_exec("php index.php p1=a1 p2=b1");

You can't use GET, POST or REQUEST from the console as they are HTTP request methods. You have to use argv, like the comments said.

If you can't modify the script to use it, you might need to build some sort of a bridge script which will convert the arguments into a GET or POST parameters and then call/fetch the original script with them. Not sure if it's worth the hassle though.

Thats not possible. GET Parameters need a GET Request to exist.

If there is no other way, you can "download" (and call) your file like this:

<?php
$resp = file_get_contents("http://www.example.com/index.php?p1=a1&p2=b1");
echo "GET call returned: $resp";
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM