0

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");
rockstardev
  • 13,479
  • 39
  • 164
  • 296
  • 1
    Duplicate http://stackoverflow.com/questions/6763997/shell-run-execute-php-script-with-parameters – ka_lin Jul 02 '14 at 07:49
  • 1
    http://stackoverflow.com/questions/4186392/php-passing-get-in-linux-command-prompt – Hanky Panky Jul 02 '14 at 07:49
  • I dont know if it's really a dupe, because I need to know how to actually pass the variables through LIKE a get request, when the underlying script can't be changed to work with argv etc – rockstardev Jul 02 '14 at 07:51

2 Answers2

0

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.

Shomz
  • 37,421
  • 4
  • 57
  • 85
0

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";
?>
PKeidel
  • 2,559
  • 1
  • 21
  • 29