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"]?
-
5Possible duplicate of PHP + curl, HTTP POST sample code?insertusernamehere– insertusernamehere2017-01-20 14:07:56 +00:00Commented Jan 20, 2017 at 14:07
Add a comment
|
1 Answer
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.