开发者

PHP $_REQUEST['do']

开发者 https://www.devze.com 2023-03-01 16:31 出处:网络
I\'m a PHP beginner. I don\'t see the answer to this question in the php manual. I know what a REQUEST superglobal does, but is \'do\' something built into PHP? I found this code in a tutorial...

I'm a PHP beginner. I don't see the answer to this question in the php manual.

I know what a REQUEST superglobal does, but is 'do' something built into PHP? I found this code in a tutorial...

if (isset($_REQUEST['do']) && ($_REQUEST['do'] == 'add') ) 

Does 'do' just mean that the form has been submitted? In the case of information coming from a link...开发者_如何学Go?


Any values set in $_COOKIE, $_GET, and $_POST will show up in $_REQUEST which means that a form that submits data to the page likely has an input element with a key of 'do' like in this example:

<input type="hidden" name="do" value="add" />

Of course it could be any html form element with a name of do, or any cookie with a name of do, or just a static query string with a name of do.


That's means a GET/POST/COOKIE (GPC) name 'do' has been submitted.

The PHP manual is very good, and can give you many answers:

http://php.net/manual/en/reserved.variables.request.php

When you submit a "request" (url with persistent COOKIES, URL-based GET variables, and POST'd variables from forms or other means), your browser sends HTML headers that contain key/value pairs that are identifiable by type (GPC) and then by name (to get a value).

So a GET variable may be presented by:

http://www.example.com/?do=yes

And the server with PHP will allow you access that do variable by:

$do = $_GET['do'];

Or:

$do = $_REQUEST['do'];

My preference is to use the actual method it was presented, ie, the $_GET['do'] call, not $_REQUEST.


It would be something submitted either via GET or POST. $_REQUEST combines both.

0

精彩评论

暂无评论...
验证码 换一张
取 消