分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

php中$_REQUEST、 $_GET、 $_POST、 $_COOKIE ?的关系和区别

发布时间:2023-09-06 01:40责任编辑:郭大石关键词:GETPOST

看到REQUEST可以通吃GET 、POST 、COOKIE 后 感觉这个$_REQUEST太强大了
是不是其他的几个超级变量就没有用了,下面对他们整体做个比较:

1.安全性 post>get

2.数据传输大小 post>get(get最大2000字节)

3.保存到收藏夹 get比较方便.

4.权限大小

首先权限大小跟php.ini文件有关

; This directive determines which super global data (G,P & C) should be; registered into the super global array REQUEST. If so, it also determines; the order in which that data is registered. The values for this directive; are specified in the same manner as the variables_order directive,; EXCEPT one. Leaving this value empty will cause PHP to use the value set; in the variables_order directive. It does not mean it will leave the super; globals array REQUEST empty.; Default Value: None; Development Value: "GP"; Production Value: "GP"; http://php.net/request-orderrequest_order = "GP"

  

这里的意思是:

; 是否将EGPCS变量注册成为全局变量.
; 如果你不希望由于用户数据而导致你脚本的全局变量变得凌乱,你需要关闭此选项
; 这个一般随着 track_vars 打开 - 在这种情况下你能够通过$HTTP_*_VARS[]存取所有的GPC变量.

这些超全局数据包括G(GET),P(POST),C(COOKIE),E(ENV),S(SERVER)。这条指令同样指定了这些数据的注册顺序,换句话说GP和PG是不一样的。注册的顺序是从左至右,即右侧的值会覆盖左侧的。比如,当设置为GPC时,COOKIE > POST > GET,依次覆盖。如果这个项被设置为空,php将会使用指令variables_order的值来指定。

在$_POST[‘name‘] = ‘post‘, $_GET [‘name‘] = ‘get‘ ,setcookie(‘name‘, ‘cookie‘, time()+3600);//先把COOKIE种上,名字为name,值为cookie。然后刷新。(COOKIE要刷新才生效)

上面三个不同的全局变量中键名都是相同的

但是print_r($_REQUEST);  后查看结果 ‘cookie‘。

结论:COOKIE的优先级最高。下来POST,最后才是GET

权限大小比较:$_COOKIE > $_POST > $_GET

另外,判断是post还是get请求的页面,最好使用:$_SERVER[‘REQUEST_METHOD‘]

php中$_REQUEST、 $_GET、 $_POST、 $_COOKIE ?的关系和区别

原文地址:https://www.cnblogs.com/average/p/8394866.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved