Solved

Command Line PHP variable

Posted on 2011-09-11
5
338 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
ID: 36520713
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36520721
>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 83

Expert Comment

by:Dave Baldwin
ID: 36520962
"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
ID: 36521703
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
ID: 36523859
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
The viewer will learn how to count occurrences of each item in an array.
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…

929 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

16 Experts available now in Live!

Get 1:1 Help Now