• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

php commandline input

html form

i have one php script :


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?
or something like that so that i can  process/manipulate/format the text output.

What should i change it inside whois.php?


2 Solutions
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:

$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=''?person='Fred Flintstone'

Your logic would step through the $parms array and find the one you are looking for and process it.
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.

williamwlkAuthor Commented:
Thanks BUDs.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now