PHP 中的 $_REQUEST

2023-10-12php开发问题
39

本文介绍了PHP 中的 $_REQUEST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有这个代码.

$message = "";

if($_REQUEST['msg'] == "new"){
    $message = "New User has been added successfully";
}else if($_REQUEST['msg'] == 'edit'){
    $message = "User has been saved successfully";
}else if($_REQUEST['msg'] == 'update'){
    $message = "User(s) has been Updated successfully";
}

谁能在这里告诉我什么是['msg']并解释$_REQUEST的功能?

can any one please tell me here what is ['msg'] and please explain the functioning of $_REQUEST?

推荐答案

$_REQUEST 是一个超级全局数组.就像 $_GET、$_POST、$_COOKIE、$_SESSION 等.这意味着它可以以数字或关联方式存储列表信息.

$_REQUEST is a super global array. Just like $_GET, $_POST, $_COOKIE, $_SESSION etc. That means it can store a list information numerically or associatively.

例如:联想:$array = array(key->value, key->value);数字:$array = array([0]->value, [1]->value);

在 $_REQUEST 或 $_POST 或 $_GET 的情况下,这些数组将存储发送到 PHP 标头的编码数据.

In the case of $_REQUEST or $_POST or $_GET these arrays will store encoded data sent to the PHP header.

例如:$_REQUEST['key'] = value;

您有一个导航项:value//对于$_GET

you have a navigation item: <a href='?key=value'>value</a> //for $_GET

PHP 会将该键-> 值编码到 url 中,并将其保存到您正在使用的超级全局数组中.要访问它,请调用:echo $_REQUEST['key'];//返回'值'

PHP will encode that key->value into the url and save it to the super global array that you are using. To access it call: echo $_REQUEST['key']; //returns 'value'

到目前为止,您的情况 msg 尚未编码到浏览器中.它需要通过不同的方式(表单、href 等)传递.所以,

In your case msg is, so far, not encoded to the browser. It needs to be passed by different means(forms, href's etc.). So,

 $_REQUEST['msg'] = 'new';
 if(isset($_REQUEST['msg'])){       //use isset() to avoid an error
    if($_REQUEST['msg'] == "new"){
        $message = "New User has been added successfully";  
    }else if($_REQUEST['msg'] == 'edit'){
        $message = "User has been saved successfully";
    }else if($_REQUEST['msg'] == 'update'){
        $message = "User(s) has been Updated successfully";
    }
}                           //returns $message = "New user..."

$_REQUEST 不建议使用,因为它很难控制处理哪些信息.$_GET 请求在 url 中显示键-> 值对.您不希望显示的信息可能不应该显示在那里.使用 $_REQUEST 用户可以通过 url 发送该键-> 值对以查看需要传递哪些信息并以其他方式利用它(谷歌跨站点请求伪造).

$_REQUEST is not suggested because it makes it hard to control what information is processed. $_GET requests show the key->value pairs in the url. Information that you don't want as visible probably shouldn't be shown there. With $_REQUEST a user can send that key->value pair over the url to see what information needs to be passed and exploit that in other ways (google cross-site request forgeries).

TL;DR : $_REQUEST['msg'] -- 'msg' 是键->值对中的一个键('new'| 'edit' | 'update' 是值)

TL;DR : $_REQUEST['msg'] -- 'msg' is a key in a key->value pair ('new'| 'edit' | 'update' being the value)

$_REQUEST 是一个超全局数组,用于保存用户可以在网站其他部分的任何范围内使用的值.

$_REQUEST is a superglobal array that saves values that can be used by the user in any scope in other parts of the website.

这篇关于PHP 中的 $_REQUEST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17