1

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

1

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.