I know this could sound a little weird but I need to pass some parameters to a $_POST array. Similar to the way apache does it, or any other web server.
Unfortunately I couldn't find libapache2-mod-php5
anywhere for my Ubuntu.
I know this could sound a little weird but I need to pass some parameters to a $_POST array. Similar to the way apache does it, or any other web server.
Unfortunately I couldn't find libapache2-mod-php5
anywhere for my Ubuntu.
That's not easily doable. You can invoke the
php-cgi
binary and pipe a fake POST request in. But you'll need to set up a whole lot of CGI environment variables:Note: Insufficient, doesn't work like that. But something like that...
It's certainly easier if you just patch the script, and let it load the $_POST array from a predefined environment variable.
Then you can invoke it like
_POST=var=123 php script.php
for simplicity.I was searching for a solution for this and came by, because it was the first hit at Google. The second one was somehow mor useful for me, because it has a really easy solution, if you have access to the PHP script and can change it.
Just insert the following lines at the beginning of your script:
This small piece of code does the trick (you may decide if you want to use $_GET or $_POST or, like I needed it, both.
After changing your script you can call it from commandline passing your args:
Have fun!
use curl to post data
curl --data "name=ii" "param1=value1¶m2=value2" http://test.com/sample.php