|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi all,
How do a run a .php file via shell script (CLI ) but providing parameters? For example to run foo.php in unix I run the command: php foo.php But how do I pass parameters like in web interface: foo.php? param1=value¶m2=value2 via command Line? The command: php foo.php?arg1=value&arg2=value2 Will not work and the just explain how to pass arguments that I understand that is not parameters like in web - I can not modify foo.php to make it get arguments, only standard web parameters (retrieved via $_GET ). Thanks Erico |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
I'm not interested in passing arguments ($argv[]), but parameters
($_GET[]): if I do it like web: www.xxx.com/foo.php?name=Erico$age=33 I will get Erico as result for $_GET['name'] but how I do the same for this same script via CLI as I can not change foo.php? it will not work if I send arguments: php foo.php name=Erico age=33 as arguments will fill $argv[] but $_GET[] will be empty. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Defranco wrote:
> Hi all, > > How do a run a .php file via shell script (CLI ) but providing > parameters? > > For example to run foo.php in unix I run the command: > > php foo.php > > But how do I pass parameters like in web interface: foo.php? > param1=value¶m2=value2 via command Line? > > The command: > > php foo.php?arg1=value&arg2=value2 > > Will not work and the just explain how to pass arguments that I > understand that is not parameters like in web - I can not modify > foo.php to make it get arguments, only standard web parameters > (retrieved via $_GET ). > > Thanks > > Erico > Just like you pass PHP arguments (like the script name): php script.php arg1 arg2 arg3 php -? provides this information. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
In our last episode,
<6f926bc9-27c9-4c1f-a8f1-077cf2d1775a@e6g2000prf.googlegroups.com>, the lovely and talented Defranco broadcast on comp.lang.php: > I'm not interested in passing arguments ($argv[]), but parameters > ($_GET[]): > if I do it like web: > www.xxx.com/foo.php?name=Erico$age=33 > I will get Erico as result for $_GET['name'] > but how I do the same for this same script via CLI as I can not change > foo.php? > it will not work if I send arguments: > php foo.php name=Erico age=33 > as arguments will fill $argv[] but $_GET[] will be empty. That's right. It is a command line interface (CLI). There is no GET. -- Lars Eighner <http://larseighner.com/> usenet@larseighner.com Countdown: 298 days to go. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Defranco wrote:
> I'm not interested in passing arguments ($argv[]), but parameters > ($_GET[]): > > if I do it like web: > www.xxx.com/foo.php?name=Erico$age=33 > > I will get Erico as result for $_GET['name'] > > but how I do the same for this same script via CLI as I can not change > foo.php? > > it will not work if I send arguments: > > php foo.php name=Erico age=33 > > as arguments will fill $argv[] but $_GET[] will be empty. > You can't. $_GET is strictly a webserver parameter. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Jerry Stuckle wrote:
> You can't. $_GET is strictly a webserver parameter. What you *could* do would be to prepend a little routine to your code which checks to see if any parameters have been passed to $argc and parses them into $_GET. -- Toby A Inkster BSc (Hons) ARCS [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux] [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 1 day, 22:26.] Best... News... Story... Ever! http://tobyinkster.co.uk/blog/2008/03/23/hypnotist/ |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Thanks for the answers!
/defranco |
|
![]() |
| Outils de la discussion | |
|
|