?
Solved

php commandline input

Posted on 2012-04-10
3
Medium Priority
?
408 Views
Last Modified: 2012-04-11
html form
Hello,

i have one php script :

http://www.xyz.com/whois.php

I want to run it from command line accepting input from command line and not like in the main page as in the picture.

#wget http://www.xyz.com/whois.php?201.192.111.22
or something like that so that i can  process/manipulate/format the text output.

What should i change it inside whois.php?

trivial?

W
0
Comment
Question by:williamwlk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
Cal_George earned 1000 total points
ID: 37829543
If you are trying to pass a parameter to whois.php, All you need to do is retrieve the query string, parse out your parameter(s) and process them. Something like this:

<?php
$parms = explode('?', $_SERVER['QUERY_STRING']);
$ipaddr = $parms[0];

The above will work with positional parameters. You can get a little fancier and use key word parameters such as "whois.php?ipaddress='201.192.111.22'?person='Fred Flintstone'

Your logic would step through the $parms array and find the one you are looking for and process it.
0
 

Assisted Solution

by:michael_martinek
michael_martinek earned 1000 total points
ID: 37830681
Your question seems to imply two different goals. If you are running the script command line it would be like "php -f <scriptfile> <params>" and you'd access the arguments via $argv[<index>]: http://us2.php.net/manual/en/reserved.variables.argv.php

If you just want to get the result back and use a web based client to retrieve it, then Cal_George is pretty much there for what you want.

Ideally, you'd want to use $_GET, $_POST, or $_REQUEST which is a combination of $_GET and $_POST. Request parameters are strongly suggested as name/value pairs set out in RFC 3986. While it's not mandatory, straying from it may result in issues down the road. As a security element, if you are expecting data only from a GET request then you should only read it from $_GET; with similar logic for POST requests.

http://us.php.net/manual/en/reserved.variables.get.php
http://us.php.net/manual/en/reserved.variables.post.php
http://us.php.net/manual/en/reserved.variables.request.php
0
 

Author Closing Comment

by:williamwlk
ID: 37833709
Thanks BUDs.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

770 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