One of ASP.net’s most attractive features is the viewstate. It is a convienent way to store arbitrary data in a persistent mechanism. In fact, it’s rather like PHP’s $_SESSION array.

There is, however, one difference. $_SESSION is unique to a user but is reused across pages. With only one window to your website, the two preform the same function. But if a user has multiple tabs or windows, $_SESSION can change in between what would otherwise be two successive page loads.

The viewstate has two functions:

Storing properties for controls and forms, Storing arbitrary data

The viewstate is responsible for ensuring a red label is still red (and doesn’t default back to black) between page loads. Controls and forms manage this transparently from the developer (excluding a non-obtrusive ViewState property on controls). There is also a viewstate on the page object. It will act like a dictionary, allowing you to save arbitrary data to it.

The viewstate is a magical thing, and it achieves that through indirection. It is what separates a browser form submission from a user actually preforming an action. Prado and Fortitude both duplicate this functionality in PHP.

For a full example, take a look at Fortitude Form’s code. But for today’s purposes, I just wanted to demonstrate how to create a simple viewstate in PHP.

count++;} else {$viewstate = new stdObject;$viewstate->count = 0;}?>Page-load count: count;?>

It preforms very similarily to $_SESSION. Although I used an object, it works just as well with an array. But it accomplishes a separate scope for each page. Frequently in PHP, pagination results are placed in $_SESSION, but that means only one set can be used at a time without butchering the rest. In a page scope, any manipulations can be done at will. And that exposes the real difference between the two: global things, like login operation or options, should be set in $_SESSION. Local, page-level or temporary things should be set in the page’s viewstate. Opening two or three or even one hundred twenty copies of that script will maintain that many instances of $viewstate->count. $_SESSION maintains only one.

Note that the security problems the ExtremeExperts article mentions are just as true with PHP as ASP.net. A manipulative user could set viewstate to a custom crafted value and disrupt the applications expectations. But that just means judicious amounts of validation are required before consuming viewstate on postbacks. Both ASP.net and PHP’s viewstate can be made secure.

viewstate 解码 php,A Viewstate for PHP相关推荐

  1. viewstate 解码 php,C#viewstate

    Viewstate 处理不是form中可以传值的标签 进行传值. 可以禁用元素的viewstate 也可以禁用页面的 Enableviewstate=false;(在配置区域写) 内网系统,互联网后台 ...

  2. 起点文学网ViewState解码分析后的结果研究

    2019独角兽企业重金招聘Python工程师标准>>> 前文[起点文学网VIEWSTATE 源码与发信收信关系的研究]详见 http://my.oschina.net/u/15803 ...

  3. viewstate 解码 php,.NET_asp.net中ViewState的用法详解,在web窗体控件设置为runat = serv - phpStudy...

    asp.net中ViewState的用法详解 在web窗体控件设置为runat = "server",这个控件会被附加一个隐藏的属性_ViewState,_ViewState存放了 ...

  4. viewstate java_ASP.NET之ViewState

    什么是ViewState? 在asp时代, 大家都知道一个html控件的值,比如input 控件值,当我们把表单提交到服务器后, 页面再刷新回来的时候, input里面的数据已经被清空. 这是因为we ...

  5. ViewState机制的解析(转自csdn)

    1         ViewState机制是什么? ViewState机制是asp.net中对同一个Page的多次请求(PostBack)之间维持Page及控件状态的一种机制.在WebForm中每次请 ...

  6. ASP.Net WebForm温故知新学习笔记:二、ViewState与UpdatePanel探秘

    原文地址:http://www.cnblogs.com/edisonchou/p/3901559.html 开篇:经历了上一篇<aspx与服务器控件探秘>后,我们了解了aspx和服务器控件 ...

  7. [转]用 ASP.NET 2.0 改进的 ViewState 加快网站速度

    本文讨论: • ViewState 如何工作 • ASP.NET 2.0 ViewState 的改进 • 使用控件状态维护功能 • 性能考虑 本文使用以下技术: ASP.NET.C# 代码下载: Vi ...

  8. [木野狐]ViewState 剖析(翻译兼笔记)

    [木野狐]ViewState 剖析(翻译兼笔记) 原文链接:ViewState: All You Wanted to Know 作者:Paul Wilson翻译:木野狐 ViewState 不是什么? ...

  9. asp.net viewState

    在web窗体控件设置为runat = "server",这个控件会被附加一个隐藏的属性_ViewState,_ViewState存放了所有控件在ViewState中的状态值.Vie ...

最新文章

  1. python一个月能掌握吗_零基础python入门分析,如何做到一个月学会(深思极恐)...
  2. numpy 打乱 numpy 数组
  3. iOS 注册密码加密 添加了时间戳 遇到的问题...
  4. 模拟storage copy 功能失败的记录
  5. 《大话设计模式》第29章-OOTV杯超级模式大赛—模式总结(四)
  6. 苹果怎么换行打字_停课不停学!推荐苹果电脑学习类软件,丰富您的假期生活...
  7. linux grep -v反向搜索:不显示目标字符串
  8. Codeforces第一次rated比赛
  9. 伪数组转化真数组_ES6 数组方法
  10. svn 版本控制操作命令
  11. 欧氏距离、巴氏距离、马氏距离的区别是什么
  12. MATLAB 2015B中文安装激活破解方法图文教程
  13. 上市融资计划书PPT模板
  14. HTML里img标签里的alt属性解释
  15. 阿里云Dataworks
  16. tv 斐讯n1原生android_斐讯T1刷原生安卓TV
  17. c语言中-next是什么意思,Java中关于nextInt()、next()和nextLine()的理解
  18. Chrome图片批量下载扩展-zzllrr imager V1.4
  19. bzoj3032 七夕祭(蓝书刷题记录)
  20. 编译原理基本定义(文法、算符文法、算符优先文法、算符优先关系表、算符优先分析过程)

热门文章

  1. 小绿豆控制器(安卓手机遥控电脑)
  2. 电磁流量计在复杂工业管道中的选型与安装
  3. 智能机井控制器的优点以及应用领域
  4. 一句话题解(20180210~)
  5. 京东商品图片爬虫+keras图像分类
  6. HTTP协议1:工作原理
  7. python---算法之二分法
  8. linux shell 鼠标事件,Bash Shellshock事件:CVE-2014-6271资料汇总
  9. 【应用案例】蓝牙BLE实现防丢器的方法
  10. 《计算机组装与维护》课程设计报告(二)