0

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"]?

XPL
  • 15
  • 4

1 Answers1

1

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,636
  • 6
  • 25
  • 36