首页 \ 问答 \ PHP会话如何工作?(How do PHP sessions work? (not “how are they used?”))

PHP会话如何工作?(How do PHP sessions work? (not “how are they used?”))

会话文件通常存储在服务器上的/tmp/ ,名为sess_{session_id} 。 我一直在看内容,无法弄清楚他们是如何工作的。

从文件获取变量名称和内容很容易。 但是PHP如何知道什么会话属于谁?

session_id似乎是完全随机的,一个IP地址可以有几个用户,如果每个用户有多个浏览器窗口打开,每个用户可以有多个会话。

那么它如何工作?


Session files are usually stored in, say, /tmp/ on the server, and named sess_{session_id}. I have been looking at the contents and cannot figure out how they really work.

Fetching the variable name and and content from the file is easy. But how does PHP know what session belongs to whom?

The session_id seems totally random and one IP address can have several users, and each user can have several sessions if they have more than one browser window open.

So how does it work?


原文:https://stackoverflow.com/questions/1535697
更新时间:2024-03-25 17:03

最满意答案

您仍然需要首先实例化它。 使用JavaScript测试:

var web3 = new Web3();
window.console.log(web3);
> Object { _requestManager: Object, currentProvider: undefined, eth: 
    Object, db: Object, shh: Object, net: Object, personal: Object, bzz: 
    Object, settings: Object, version: Object, 2 more… }

我没有使用TypeScript的经验,但你明白了。 web3js提供了库,您需要初始化它才能使用。 它基本上是链接文档页面的第一行。


You still need to instantiate it first. Tested with JavaScript:

var web3 = new Web3();
window.console.log(web3);
> Object { _requestManager: Object, currentProvider: undefined, eth: 
    Object, db: Object, shh: Object, net: Object, personal: Object, bzz: 
    Object, settings: Object, version: Object, 2 more… }

I have no experience with TypeScript though, but you get the idea. web3js is providing the library, and you need to initialize it to work with. It's basically the first line of the linked documentation page.

相关问答

更多
  • 您仍然需要首先实例化它。 使用JavaScript测试: var web3 = new Web3(); window.console.log(web3); > Object { _requestManager: Object, currentProvider: undefined, eth: Object, db: Object, shh: Object, net: Object, personal: Object, bzz: Object, settings: Object, vers ...
  • 实际上,我们不能只从新创建的地址发送事务。 我们必须使用私钥签署此交易。 例如,我们可以将ethereumjs-tx模块用于ethereumjs-tx 。 const Web3 = require('web3') const Tx = require('ethereumjs-tx') let web3 = new Web3( new Web3.providers.HttpProvider( "https://ropsten.infura.io/---your api key-----" ) ...
  • 这是描述关于所有交易呼叫的一般信息(气体限制,价格,乙醚发送量等)的transactionObject。 你发布的JS代码是使用web3库。 这不是对合同API的直接调用。 web3库将其转换为RPC。 transactionObject来自所有的合约参数。 还有另外一个参数,它是合约调用结果的回调(参见这里 )。 这些是从文档中描述的transactionobject对象的所有选项: from:String - 发送帐户的地址。 如果未指定,请使用web3.eth.defaultAccount属性。 to ...
  • https://github.com/robinhoodcoin/robinhoodcoin.github.io/blob/master/metamask.html#L118上的一行有一个错字。 它写道: self.myContractInstance = self.MyContract.at(self.address); 但地址存储在self.contractAddress ,所以它应该是: self.myContractInstance = self.MyContract.at(self.contra ...
  • 外部拥有帐户(EOA)的随机数从0开始,每次交易增加1。 因此,帐户发送的第一个事务需要有nonce 0,第二个需要有nonce 1等。 要获取正确的当前现时,可以使用web3.eth.getTransactionCount(
    ) 。 The nonce for an externally owned account (EOA) starts at 0 and increases by one with each transaction. So the very first transact ...
  • 要添加到maptuhec所说的内容,在Web3中调用“状态改变”功能或改变状态的事务时,必须签名! 下面是一个例子,当你试图调用一个公共函数(甚至是一个公共契约变量)时,它只是读取(或“查看”)并从你的智能合约返回一个值而不是改变它的状态,我们不需要必须指定一个事务正文然后将其签名为事务,因为它不会改变我们的合同状态。 contractInstance.methods.aPublicFunctionOrVariableName().call().then( (result) => {console.log( ...
  • 您没有在您的go文件中设置合同地址: https : //github.com/regcostajr/go-web3/blob/master/test/eth/eth-contract_test.go#L75 You are not setting the contract address in your go file: https://github.com/regcostajr/go-web3/blob/master/test/eth/eth-contract_test.go#L75
  • 回调没有被立即调用,问题是你没有发送一个实际的地址,这应该是一个字符串,你发送一个数字: 0x64319ca297239d8652a0b5f0f12dd6666cb0e05b == 5.720054584403591e+47 你得到0因为你发送的无效地址在映射中不存在: mapping (address=>uint) map23; 如果它不存在,它将返回uint的默认值,该值为零。 发送一个字符串,它将工作: BasicToken.getNum('0x64319ca297239d8652a0b5f0f1 ...
  • 您正在寻找eth_getBlockByNumber API。 在Web3中,此调用使用getBlock函数实现,该函数实现eth_getBlockByNumber和eth_getBlockByHash。 参数: 1:QUANTITY | TAG - 块编号的整数,或字符串“earliest”,“latest”或“pending”,如默认块参数中所示。 2:Boolean - 如果为true,则返回完整的事务对象,如果为false,则仅返回事务的哈希值。 参数1的“最新”是您正在寻找的。 You are lo ...
  • 你能试试看吗? 我认为onload正在解决这个问题。 $(window).load function() { web3.eth.getAccounts(function(err,accs) { if (err != null) { alert("There was an error fetching your accounts."); return; } if (accs.length == 0) { alert("Couldn't ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)