关于session会话的问题 php
本帖最后由 redenn 于 2012-11-11 15:37:21 编辑
今天看了关于session的视频。 那位老师说,当浏览器访问服务端的时候创建一次会话。 然后 php页面中session_start在服务器创建了一个
session_id,它把session_id以cookie的方式返回给浏览器。浏览器cookie带着这个id去访问其它的页面,从而能找到服务器端的这个id对应
的session文件,从而执行数据交流。
但,有一些问题不明白:
1.服务器把session_id传递给浏览器的cookie,这个cookie是不是在浏览器客户端的默认cookie文件夹里确实存在的呢,存在的时间又是多少
呢?
2.当我访问网站时如何能确确实实地得到 那个session_start为我准备的会话的session_id。和其中中的内容。
3. 通过这个session_id如何实现,curl模拟登陆呢?
希望各位好心的朋友,能为我解惑啊,或给我一些思路。
------解决方案--------------------
1、session_id 存在于浏览器搜使用的内存里,而不是对应的cookie文件中。因为session_id的生存时间是浏览器打开期间,而cookie文件是在浏览器关闭时才创建,用于保存尚未过期的cookie变量
2、session_start 后,你可以用 session_id 函数获取当前的 session_id,用 $_SESSION 数组管理 session 变量
3、不是通过 session_id 模拟登陆,而是通过 cookie 模拟登陆
curl 提供了
CURLOPT_COOKIE 发送 cookie 变量
CURLOPT_COOKIEFILE 发送 cookie 文件
CURLOPT_COOKIEJAR 接收 cookie 到文件
------解决方案--------------------
1.session的生存时间不是1440秒(24分钟)么,而且浏览器禁用了cookie,则session_start()生成的session_id对于浏览器的操作都会无效。所以session_id不是与cookie有关么?
2.因为我是想访问别人的网站, 然后得到我访问中别人网站的session_start()产生的session_id,这怎么获得。
3.因为,许多网站都是以session做为身份验证,而我用cookie就无效了。所以想以session_id所对应的文件里的内容,作为模拟登陆的验证。
------解决方案--------------------
该回复于2012-12-08 14:13:03被管理员删除

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor
