You can run a php script from command line by this: php youscript.php
My question: Is it possible to pass the post data to the script like php yourscript.sh post1=test post2=test2
so that you can get this data by $_POST["post1"]
?
Asked
Active
Viewed 1,139 times
0

XPL
- 15
- 6
-
5Possible duplicate of [PHP + curl, HTTP POST sample code?](http://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code) – insertusernamehere Jan 20 '17 at 14:07
1 Answers
2
See: http://php.net/manual/en/function.getopt.php
Example #1 getopt() example: The basics
<?php
// Script example.php
$options = getopt("f:hp:");
var_dump($options);
?>
shell> php example.php -fvalue -h
array(2) {
["f"]=>
string(5) "value"
["h"]=>
bool(false)
}
$_POST
is set by Apache, which gets $_POST
data from a HTTP connection. If you're looking to call php directly via the command line, apache is never called and hence $_POST, $_GET, $_REQUEST etc, these are never set.

Moe
- 4,744
- 7
- 28
- 37