Solved

Command Line PHP variable

Posted on 2011-09-11
5
335 Views
Last Modified: 2012-05-12
I am able to issue command line php such as:

C:\>php test.php

And everything runs fine.

But, when I try to send a variable:

C:\>php test.php?my_variable=hello

It fails with a:

Could not open input file test.php?my_variable=hello

Where am I going wrong?
0
Comment
Question by:hrolsons
5 Comments
 
LVL 15

Expert Comment

by:Minh Võ Công
Comment Utility
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
>Where am I going wrong?

the system try to find the file test.php?my_variable=hello (and not file test.php as you want)
C:\>php test.php hello

Open in new window


in you code (test php) :
<?PHP

echo $_SERVER["argv"][1];

?>

Open in new window

0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
"test.php?my_variable=hello" is something a web server would recognize as a URL with a query string.  That is not the way it is done on the command line because the command line version does not run thru the web server.  I think you need to come to an understanding of the difference because you have several questions here that confuse those two different ways of running PHP.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Instead of running PHP from the command line, I always put my scripts on my web server and test them there, over the internet, in the live environment that is exactly where they will run, when they are released into the wild.  It saves me a lot of confusion.  You might want to think about that.  My "build process" usually consists of Save->Ftp->Refresh.  Lather, rinse, repeat.  Easy!
0
 

Author Comment

by:hrolsons
Comment Utility
Ray,

I totally see what you're saying, but in this case, the php file is manipulating images(adding the border), and will never leave my machine.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now