473,695 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6791
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_l ine = !strlen($_SERVE R['HTTP_HOST']);

if ($debugging && $from_command_l ine)
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_l ine)".
Never use just "if ($from_command_ line)" though!

e.g.

<?php
if ($debugging)
{
echo "\n<pre>\n" ;
echo "\n<b>\$_PO ST</b>\n"; var_dump($_POST );
echo "\n<b>\$_GE T</b>\n"; var_dump($_GET) ;
echo "\n<b>\$_COOKIE </b>\n"; var_dump($_COOK IE);
echo "\n<b>\$_SERVER </b>\n"; var_dump($_SERV ER);
echo "\n<b>\$_SESSIO N</b>\n"; var_dump($_SESS ION);
echo "\n</pre>\n";
}
?>

at the end of your code can be useful.

When finished debugging, just set $debugging=FALS E.

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

May 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7673
by: Robert | last post by:
I am using the php4-cgi Debian package which is based on PHP 4.3.4. I have problems when running php4 on the command line. If I say something like $ php4 index.cgi a number of variables are not initialized. For example, $HTTP_GET_VARS is not set. To get it set, here's my workaround:
6
2930
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming yesterday but someone kindly suggested that I'd have better luck here. So here goes! My program ignores any command line arguments, or at least it's supposed to. However, when I pass any command line arguments to the program, the behaviour of one of the functions changes mysteriously. I have...
1
2449
by: Rune Jacobsen | last post by:
Hi, I've been trying to figure this one out, but my experience just doesn't have what it takes... :| I am writing an application that reads an XML file and displays the contents in various ways to the end user. This works fine. My challenge lies in the fact that these XML files are generated by various (third party) applications. Which application generates them depends on the user, the country they are in, their personal preferences,...
5
3405
by: clsmith66 | last post by:
I've been asked to find out if a project is possible, but I'm not having much luck finding the information I need, I hope some one can help. I need to see if I can build a windows service on the fly customized to a specific client. Is it possible to run the VS command line tool through another application (VB.NET)? I'm thinking I can run the tools as a process and pass the necessary parameters to the process, but I'm not sure how to go...
0
1076
by: DumbNewbie | last post by:
Hi, My post build command line is currently moving assemblies and exes around to the correct locations after the build as expected. I was wondering if there was a way I could get the current version from the main exe and use this as part of the directory string to which I want to move the files, i.e. d:\distrib\app\<v1.1.1>\assemblies\blah\blah\blah Also if there a way I can get it to happen only for a release build?
2
8107
by: Aaron | last post by:
I'm trying to pull data from a website and read it into a file the I can parse. I've done the before to site without post variables but I can seem to get my statments to work with the post. Can someone help me out? below is the code I have so far. Thank in advance... $url="www.somesitethatneedspostvariables.com"; $postdata = http_build_query( array( 'postvarname1' ='value1',
11
16891
by: imtiazalikhan | last post by:
hi i am trying to sum 10 numbers passing them by command line line argument but the problem is it only work with 1 and if i passing other numbers then again it will show the result of number1: code: class arguments { public static void main(String args) { int sum=0; int avg=sum/10;
7
3361
by: amygdala | last post by:
Hi all, I'm starting this new project in which I'ld like to implement sort of a design pattern I have seen being used in the CodeIgniter framework. Basically, the site will examine the URI and based on the segments of the URI it will fire up some controller class, for instance, say I have an inbox in which end-users can view messages they got from other users, they'ld start at:
3
2002
by: smitty1e | last post by:
Just a fun exercise to unify some of the major input methods for a script into a single dictionary. Here is the output, given a gr.conf file in the same directory with the contents stated below: smitty@localhost ~/proj/mddl4/test $ ./inputs.py {'source_db': '/home/sweet/home.db'} smitty@localhost ~/proj/mddl4/test $ source_db="test_env" ./inputs.py {'source_db': 'test_env'} smitty@localhost ~/proj/mddl4/test $ ./inputs.py -f "test_cli"
1
1929
by: Zygor1 | last post by:
Without going into details; I have the need to pass a string containing double backslashes \\ from the DOS command line and convert these to single backslashes in the code. The problem is if I do this from within perl code directly it is no problem but when I attempt to pass a string from the command line, it seems to lose something in the translation and when I try to do the replace it does not work. So the question is HOW to pass the...
0
8638
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8857
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8831
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4346
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2278
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1979
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.