Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

If an arg is not there...

4 views
Skip to first unread message

bit-n...@hotmail.com

unread,
Jun 2, 2017, 3:58:54 PM6/2/17
to
If I pass an arg to a PHP prog, how do I read it? Like site.com/prog.php?arg=cool - how do I read arg and get the word "cool" in my program?

And - if an arg is not there, like, say above, the argument "arg2" is not there, only "arg" - whatever method is used for reading args (eg. $_REQUEST something or whatever), that will be blank for arg2, right? (eg. $_REQUEST["arg2"] etc.)

J.O. Aho

unread,
Jun 2, 2017, 4:45:44 PM6/2/17
to
On 06/02/17 21:58, bit-n...@hotmail.com wrote:
> If I pass an arg to a PHP prog, how do I read it? Like site.com/prog.php?arg=cool - how do I read arg and get the word "cool" in my program?

$_GET[] if you just expect requests which has the value in the URL as in
your example.

$_REQUEST[] if you expect both POST (<form><input type='text'...><input
type='submit'...></form>) and GET (as in your example).



> And - if an arg is not there, like, say above, the argument "arg2" is not there, only "arg" - whatever method is used for reading args (eg. $_REQUEST something or whatever), that will be blank for arg2, right? (eg. $_REQUEST["arg2"] etc.)

If arg2 is sent but with an empty value, then the $_GET['arg2'] will be
empty, if arg2 is completely missing from the request, then there ain't
a $_GET['arg2']


Please read at least these pages:
http://php.net/manual/en/reserved.variables.get.php
http://php.net/manual/en/reserved.variables.post.php
http://php.net/manual/en/reserved.variables.request.php
http://php.net/manual/en/function.isset.php
http://php.net/manual/en/function.empty.php

There you will find the answers you look for.


--

//Aho
0 new messages