469,592 Members | 2,038 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

Passing $_POST variables to command line php

Hi all! I'm trying to test some php script using the command line php.exe.
Is there any way to pass the $_POST variables? I know how to pass the $_GET
variables, but I don't know how to do this for the $_POST ones. Thank you
all!
Matthew
May 16 '06 #1
1 6623
Infiliset wrote:
Hi all! I'm trying to test some php script using the command line php.exe.
Is there any way to pass the $_POST variables? I know how to pass the $_GET
variables, but I don't know how to do this for the $_POST ones. Thank you
all!


Easiest and most flexible way to do this is to include at the top of your
script:

<?php
$debugging = TRUE;
$from_command_line = !strlen($_SERVER['HTTP_HOST']);

if ($debugging && $from_command_line)
include "test_post_vars.php";
?>

Then populate test_post_vars.php with your $_POST variables. For example:

<?php
$_POST['username']='henry';
$_POST['password']='secret';
?>

You may want to include various other parts of debugging code later on in
the file using "if ($debugging)" or "if ($debugging && $from_command_line)".
Never use just "if ($from_command_line)" though!

e.g.

<?php
if ($debugging)
{
echo "\n<pre>\n";
echo "\n<b>\$_POST</b>\n"; var_dump($_POST);
echo "\n<b>\$_GET</b>\n"; var_dump($_GET);
echo "\n<b>\$_COOKIE</b>\n"; var_dump($_COOKIE);
echo "\n<b>\$_SERVER</b>\n"; var_dump($_SERVER);
echo "\n<b>\$_SESSION</b>\n"; var_dump($_SESSION);
echo "\n</pre>\n";
}
?>

at the end of your code can be useful.

When finished debugging, just set $debugging=FALSE.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

May 17 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Edd Dawson | last post: by
1 post views Thread by Rune Jacobsen | last post: by
reply views Thread by DumbNewbie | last post: by
2 posts views Thread by Aaron | last post: by
7 posts views Thread by amygdala | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.