You are here: Re: Passing $_POST variables to command line php « PHP Programming Language « IT news, forums, messages
Re: Passing $_POST variables to command line php

Posted by Toby Inkster on 05/17/06 09:51

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация