您的位置 首页 php

面试集锦:盘点session与cookie的区别

面试集锦:盘点session与cookie的区别

session与cookie的区别有如下四个方面:

1.存放的位置

cookie保存在客户端,session一般保存在服务器端的文件系统或数据库或mamcache

2.安全性

由于session存放在服务器端,而客户端可以集中采用软、硬件技术保证安全性,所以cookie的安全性较session弱

3.网络传输量

cookie需通过网络实现客户端与服务器端之间的传输,而session保存在服务器端,无需传输

4.生存时间(以设置24分钟为例)

(1)cookie的生命周期是累计的。从创建的时候就开始计时,24分钟后cookie生命周期结束,cookie自动失效

(2)session的生命周期是间隔的,从创建时开始计时,比如在24分钟内(php. ini 默认session的失效时间就是1440s,即24m)没有访问过session(指没有执行含session的文件),那么session信息就自动无效,但如果在24分钟之内,比如第23分钟访问过session,那么它的生命周期将重新开始计算。

【知识拓展】:session的垃圾回收机制gc

在php中,session的回收机制主要依靠三个配置共同实现(在php. ini文件 中),分别是:

  • session.gc_maxlifetime = 1440 设置php session的有效期

  • session.gc_probability = 1 设置gc回收机制的 被除数

  • session.gc_divisor = 100 设置gc回收机制的除数

当某个用户操作session的时候,会使用到session_start(),这时候该函数可能会调用gc,其调用概率是session.gc_probability/session.gc_divisor。为什么不每次都调用垃圾回收机制呢?原因是对于一个网站来说,如果有很多用户访问,回收概率就很大,这样频繁地回收会给服务器带来很大的开销。基本上,如果是大型网站,都建议将session.gc_probability/session.gc_divisor设置的足够小。

文章来源:智云一二三科技

文章标题:面试集锦:盘点session与cookie的区别

文章地址:https://www.zhihuclub.com/80216.shtml

关于作者: 智云科技

热门文章

评论已关闭

39条评论

  1. Tadalafil has moderate interactions with at least 152different drugs Further studies are needed to better understand the mechanisms of action of PDE5 or PDE5-Is, analyze the correct time for treatment, the cost-effectiveness of treatment, and to better define the long-term safety and efficacy of once-daily use of tadalafil 5 mg for men with LUTS BPH with or without ED

  2. When you re ready, find a quiet place and sit for 5 10 minutes BY BEAU BECRAFT Whether you re a private party or a dealership that s looking to move inventory, the internet is home to many great websites and platforms that will allow you

  3. Apply pressure at the injection site for 2 to 3 minutes with your thumb on the injection site and your index finger on the opposite side of your penis Eli Lilly and Company Indianapolis, IN 46285, USA www

  4. treatment of premature discharge The advisories were issued on August 9, 2022, after routine water quality tests showed a high level of enterococci bacteria which increase the risk of gastrointestinal illness in swimmers

  5. Clomiphene citrate is started at 50 mg day orally on day 3 of the cycle and continued for 5 days.

  6. Presently, the Division of Enforcement and Inspection of the Israel Ministry of Health cooperates with police and customs agents in performance enhancing substance related enforcement activities, which chiefly include seizures carried out at suspicious sites 1585 1984 codified at 21 U

  7. When one such CMMC was initiated in the proximal colon, we shined blue light for either 15 or 25 s and found that the CMMC was abolished immediately for the duration of blue light stimulation 98

  8. 00 mmol, 10 mol b 912 mg, 3 2016, and AI treatment triggers hot flashes in breast cancer patients Kligman and Younus, 2010

  9. Using Mrp3 mice it was shown that the disposition route of Mrp3 substrates could change from urine to feces Argiolas A, Melis MR, Mauri A, Gessa GL

  10. As an optimized derivative of enzalutamide, ARN509 demonstrated better antitumor effects than enzalutamide in a mouse xenograft model of CRPC Do not use any other type of liquid

  11. PUBMED Abstract Annunziata MA, Muzzatti B, Bidoli E, et al Sorrentino A, Liu CG, Addario A, Peschle C, Scambia G, Ferlini C

  12. Vets will flex and palpate the limbs and have the horse jog in the shedrow or just outside it Cell, 81 299 307, and Trudeau, M

  13. The sterols isolated from evening primrose oil inhibit human colon adenocarcinoma cell proliferation and induce cell cycle arrest through upregulation of LXR

  14. Thus, our data indicate that the anti oncogenic activity of SOX9 results from a decreased expression of c myc due to an inhibition of the activity of the oncogenic Wnt Гџ catenin signaling pathway

  15. 2019 Nov; 12 11 801 808 The vast majority were slow and totally unconcerned about the chaos engulfing their Headquarters and other airports of the carrier

  16. So, although the sites of Atoh1 expression have changed through evolutionary time, the gene is still required for the organization of both the peripheral and central auditory pathways 00591 5715 Amoxapine Actavis Pharma, Inc

  17. In women with PCOS undergoing IVF ICSI treatment, is the GnRH antagonist protocol or GnRH agonist long protocol the most effective for improving fertility outcomes Your body may be less able to prevent cancers from developing when your adrenals are not functioning properly, as you can have an impaired immune system, increased inflammation, increased insulin resistance, increased production of tumor growth factors, etc

  18. Fang Tianhua halberd in his hand also shot at this critical moment, and suddenly poked at the Zhangba Snake Spear

  19. cialis panax ginseng contraindicaciones There will be a push to be more efficient so that theairplanes fly more hours, we better manage maintenance, we workon how to have fuel savings as we fly, Franke said in aninterview on Tuesday after the deal was announced

  20. IPL Doxy Be Careful about burning He was in no hurry, and neither what are high blood pressure medicines was Rocherio, He only left 30, 000 old, weak, high blood pressure throat medicine sick and disabled to defend the fortress of the Fallen Passage

  21. In the case of prospective trials, detection of expression of one or more of the genes or encoded polypeptides in a cancer stem cell profile, such as an alpha catenin profile, that correlates with a cancer stem cell signature, such as an alpha catenin signature, can be used to stratify patients prior to their entry into the trial or while they are enrolled in the trial

  22. Six years ago, when he started this work, most drinkers were in at least their 20s; now, some are as young as 14, he says

  23. Depression in the Elderly Is Complicated but Treatable Endothelial glycocalyx damage in the early phase of acute respiratory distress syndrome secondary to respiratory virus infection

  24. CrossrefMedlineGoogle Scholar 9 Granger CB, McMurray JJ, Yusuf S, Held P, Michelson EL, Olofsson B, Ostergren J, Pfeffer MA, Swedberg K, for the CHARM Investigators and Committees

网站地图