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 namedsess_{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
最满意答案
您仍然需要首先实例化它。 使用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 ...
-
web3 balanceOf始终为0(web3 balanceOf always 0)[2022-09-16]
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 ... -
Web3.py事务不在以太坊Rinkby testnet上广播(Web3.py transactions are not broadcast on Ethereum Rinkby testnet)[2023-03-31]
外部拥有帐户(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( ...
-
与Golang Web3松露(Truffle with Golang Web3)[2023-04-13]
您没有在您的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 -
web3立即触发回调(web3 instantly firing callback)[2022-11-02]
回调没有被立即调用,问题是你没有发送一个实际的地址,这应该是一个字符串,你发送一个数字: 0x64319ca297239d8652a0b5f0f12dd6666cb0e05b == 5.720054584403591e+47 你得到0因为你发送的无效地址在映射中不存在: mapping (address=>uint) map23; 如果它不存在,它将返回uint的默认值,该值为零。 发送一个字符串,它将工作: BasicToken.getNum('0x64319ca297239d8652a0b5f0f1 ... -
以太坊最新交易(Ethereum latest transactions)[2022-02-19]
您正在寻找eth_getBlockByNumber API。 在Web3中,此调用使用getBlock函数实现,该函数实现eth_getBlockByNumber和eth_getBlockByHash。 参数: 1:QUANTITY | TAG - 块编号的整数,或字符串“earliest”,“latest”或“pending”,如默认块参数中所示。 2:Boolean - 如果为true,则返回完整的事务对象,如果为false,则仅返回事务的哈希值。 参数1的“最新”是您正在寻找的。 You are lo ... -
未捕获的ReferenceError:在window.onload中未定义web3(Uncaught ReferenceError: web3 is not defined at window.onload)[2022-11-12]
你能试试看吗? 我认为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 ...